Example #1
0
static bRC setAcl(bpContext *ctx, acl_pkt *ap)
{
   int status;
   unser_declare;
   uint32_t acl_name_length;
   uint32_t xattr_value_length;
   POOL_MEM xattr_value(PM_MESSAGE),
            acl_name(PM_MESSAGE);

   plugin_ctx *p_ctx = (plugin_ctx *)ctx->pContext;

   if (!p_ctx) {
      return bRC_Error;
   }

   unser_begin(ap->content, ap->content_length);
   while (unser_length(ap->content) < ap->content_length) {
      unser_uint32(acl_name_length);

      /*
       * Decode the ACL name including the \0
       */
      acl_name.check_size(acl_name_length);
      unser_bytes(acl_name.c_str(), acl_name_length);

      unser_uint32(xattr_value_length);

      /*
       * Decode the actual ACL data as stored as XATTR.
       */
      xattr_value.check_size(xattr_value_length);
      unser_bytes(xattr_value.c_str(), xattr_value_length);

      status = ceph_lsetxattr(p_ctx->cmount, ap->fname, acl_name.c_str(),
                              xattr_value.c_str(), xattr_value_length, 0);
      if (status < 0) {
         berrno be;

         Jmsg(ctx, M_ERROR, "ceph_lsetxattr(%s) failed: %s\n", ap->fname, be.bstrerror(-status));
         return bRC_Error;
      }
   }

   unser_end(ap->content, ap->content_length);

   return bRC_OK;
}
Example #2
0
bool decompress_data(JCR *jcr,
                     const char *last_fname,
                     int32_t stream,
                     char **data,
                     uint32_t *length,
                     bool want_data_stream)
{
   Dmsg1(400, "Stream found in decompress_data(): %d\n", stream);
   switch (stream) {
   case STREAM_COMPRESSED_DATA:
   case STREAM_SPARSE_COMPRESSED_DATA:
   case STREAM_WIN32_COMPRESSED_DATA:
   case STREAM_ENCRYPTED_FILE_COMPRESSED_DATA:
   case STREAM_ENCRYPTED_WIN32_COMPRESSED_DATA: {
      uint32_t comp_magic, comp_len;
      uint16_t comp_level, comp_version;

      /*
       * Read compress header
       */
      unser_declare;
      unser_begin(*data, sizeof(comp_stream_header));
      unser_uint32(comp_magic);
      unser_uint32(comp_len);
      unser_uint16(comp_level);
      unser_uint16(comp_version);
      unser_end(*data, sizeof(comp_stream_header));
      Dmsg4(400, "Compressed data stream found: magic=0x%x, len=%d, level=%d, ver=0x%x\n",
            comp_magic, comp_len, comp_level, comp_version);

      /*
       * Version check
       */
      if (comp_version != COMP_HEAD_VERSION) {
         Qmsg(jcr, M_ERROR, 0, _("Compressed header version error. version=0x%x\n"), comp_version);
         return false;
      }

      /*
       * Size check
       */
      if (comp_len + sizeof(comp_stream_header) != *length) {
         Qmsg(jcr, M_ERROR, 0, _("Compressed header size error. comp_len=%d, msglen=%d\n"),
              comp_len, *length);
         return false;
      }

      /*
       * Based on the compression used perform the actual decompression of the data.
       */
      switch (comp_magic) {
#ifdef HAVE_LIBZ
         case COMPRESS_GZIP:
            switch (stream) {
            case STREAM_SPARSE_COMPRESSED_DATA:
               return decompress_with_zlib(jcr, last_fname, data, length, true, true, want_data_stream);
            default:
               return decompress_with_zlib(jcr, last_fname, data, length, false, true, want_data_stream);
            }
#endif
#ifdef HAVE_LZO
         case COMPRESS_LZO1X:
            switch (stream) {
            case STREAM_SPARSE_COMPRESSED_DATA:
               return decompress_with_lzo(jcr, last_fname, data, length, true, want_data_stream);
            default:
               return decompress_with_lzo(jcr, last_fname, data, length, false, want_data_stream);
            }
#endif
#ifdef HAVE_FASTLZ
         case COMPRESS_FZFZ:
         case COMPRESS_FZ4L:
         case COMPRESS_FZ4H:
            switch (stream) {
            case STREAM_SPARSE_COMPRESSED_DATA:
               return decompress_with_fastlz(jcr, last_fname, data, length, comp_magic, true, want_data_stream);
            default:
               return decompress_with_fastlz(jcr, last_fname, data, length, comp_magic, false, want_data_stream);
            }
#endif
         default:
            Qmsg(jcr, M_ERROR, 0, _("Compression algorithm 0x%x found, but not supported!\n"), comp_magic);
            return false;
      }
      break;
   }
   default:
#ifdef HAVE_LIBZ
      switch (stream) {
      case STREAM_SPARSE_GZIP_DATA:
         return decompress_with_zlib(jcr, last_fname, data, length, true, false, want_data_stream);
      default:
         return decompress_with_zlib(jcr, last_fname, data, length, false, false, want_data_stream);
      }
#else
      Qmsg(jcr, M_ERROR, 0, _("Compression algorithm GZIP found, but not supported!\n"));
      return false;
#endif
   }
}
Example #3
0
struct container* retrieve_container_by_id(containerid id) {
	struct container *c = (struct container*) malloc(sizeof(struct container));

	init_container_meta(&c->meta);

	unsigned char *cur = 0;
	if (destor.simulation_level >= SIMULATION_RESTORE) {
		c->data = malloc(CONTAINER_META_SIZE);

		pthread_mutex_lock(&mutex);

		if (destor.simulation_level >= SIMULATION_APPEND)
			fseek(fp, id * CONTAINER_META_SIZE + 8, SEEK_SET);
		else
			fseek(fp, (id + 1) * CONTAINER_SIZE - CONTAINER_META_SIZE + 8,
			SEEK_SET);

		fread(c->data, CONTAINER_META_SIZE, 1, fp);

		pthread_mutex_unlock(&mutex);

		cur = c->data;
	} else {
		c->data = malloc(CONTAINER_SIZE);

		pthread_mutex_lock(&mutex);

		fseek(fp, id * CONTAINER_SIZE + 8, SEEK_SET);
		fread(c->data, CONTAINER_SIZE, 1, fp);

		pthread_mutex_unlock(&mutex);

		cur = &c->data[CONTAINER_SIZE - CONTAINER_META_SIZE];
	}

	unser_declare;
	unser_begin(cur, CONTAINER_META_SIZE);

	unser_int64(c->meta.id);
	unser_int32(c->meta.chunk_num);
	unser_int32(c->meta.data_size);

	if(c->meta.id != id){
		WARNING("expect %lld, but read %lld", id, c->meta.id);
		assert(c->meta.id == id);
	}

	int i;
	for (i = 0; i < c->meta.chunk_num; i++) {
		struct metaEntry* me = (struct metaEntry*) malloc(
				sizeof(struct metaEntry));
		unser_bytes(&me->fp, sizeof(fingerprint));
		unser_bytes(&me->len, sizeof(int32_t));
		unser_bytes(&me->off, sizeof(int32_t));
		g_hash_table_insert(c->meta.map, &me->fp, me);
	}

	unser_end(cur, CONTAINER_META_SIZE);

	if (destor.simulation_level >= SIMULATION_RESTORE) {
		free(c->data);
		c->data = 0;
	}

	return c;
}