1 // -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
2 // vim: ts=8 sw=2 smarttab
4 * All operations via the rados gateway are carried out by
5 * small classes known as RGWOps. This class contains a req_state
6 * and each possible command is a subclass of this with a defined
7 * execute() method that does whatever the subclass name implies.
8 * These subclasses must be further subclassed (by interface type)
9 * to provide additional virtual methods such as send_response or get_params.
23 #include <boost/optional.hpp>
24 #include <boost/utility/in_place_factory.hpp>
25 #include <boost/function.hpp>
27 #include "common/armor.h"
28 #include "common/mime.h"
29 #include "common/utf8.h"
30 #include "common/ceph_json.h"
31 #include "common/utf8.h"
32 #include "common/ceph_time.h"
34 #include "rgw_common.h"
35 #include "rgw_rados.h"
37 #include "rgw_bucket.h"
40 #include "rgw_quota.h"
43 #include "rgw_torrent.h"
46 #include "include/assert.h"
48 using ceph::crypto::SHA1
;
58 class StrategyRegistry
;
70 int do_init_permissions();
71 int do_read_permissions(RGWOp
* op
, bool only_bucket
);
78 virtual ~RGWHandler();
80 virtual int init(RGWRados
* store
,
82 rgw::io::BasicClient
* cio
);
84 virtual int init_permissions(RGWOp
*) {
88 virtual int retarget(RGWOp
* op
, RGWOp
** new_op
) {
93 virtual int read_permissions(RGWOp
* op
) = 0;
94 virtual int authorize() = 0;
95 virtual int postauth_init() = 0;
96 virtual int error_handler(int err_no
, std::string
* error_content
);
97 virtual void dump(const string
& code
, const string
& message
) const {}
102 void rgw_bucket_object_pre_exec(struct req_state
*s
);
105 * Provide the base class for all ops.
110 RGWHandler
*dialect_handler
;
112 RGWCORSConfiguration bucket_cors
;
114 RGWQuotaInfo bucket_quota
;
115 RGWQuotaInfo user_quota
;
118 int do_aws4_auth_completion();
120 virtual int init_quota();
124 dialect_handler(nullptr),
130 virtual ~RGWOp() = default;
132 int get_ret() const { return op_ret
; }
134 virtual int init_processing() {
135 op_ret
= init_quota();
142 virtual void init(RGWRados
*store
, struct req_state
*s
, RGWHandler
*dialect_handler
) {
145 this->dialect_handler
= dialect_handler
;
147 int read_bucket_cors();
148 bool generate_cors_headers(string
& origin
, string
& method
, string
& headers
, string
& exp_headers
, unsigned *max_age
);
150 virtual int verify_params() { return 0; }
151 virtual bool prefetch_data() { return false; }
153 /* Authenticate requester -- verify its identity.
155 * NOTE: typically the procedure is common across all operations of the same
156 * dialect (S3, Swift API). However, there are significant exceptions in
157 * both APIs: browser uploads, /info and OPTIONS handlers. All of them use
158 * different, specific authentication schema driving the need for per-op
159 * authentication. The alternative is to duplicate parts of the method-
160 * dispatch logic in RGWHandler::authorize() and pollute it with a lot
161 * of special cases. */
162 virtual int verify_requester(const rgw::auth::StrategyRegistry
& auth_registry
) {
163 /* TODO(rzarzynski): rename RGWHandler::authorize to generic_authenticate. */
164 return dialect_handler
->authorize();
166 virtual int verify_permission() = 0;
167 virtual int verify_op_mask();
168 virtual void pre_exec() {}
169 virtual void execute() = 0;
170 virtual void send_response() {}
171 virtual void complete() {
174 virtual const string
name() = 0;
175 virtual RGWOpType
get_type() { return RGW_OP_UNKNOWN
; }
177 virtual uint32_t op_mask() { return 0; }
179 virtual int error_handler(int err_no
, string
*error_content
);
182 class RGWGetObj
: public RGWOp
{
184 seed torrent
; // get torrent
185 const char *range_str
;
187 const char *if_unmod
;
188 const char *if_match
;
189 const char *if_nomatch
;
190 uint32_t mod_zone_id
;
196 ceph::real_time mod_time
;
197 ceph::real_time lastmod
;
198 ceph::real_time unmod_time
;
199 ceph::real_time
*mod_ptr
;
200 ceph::real_time
*unmod_ptr
;
201 map
<string
, bufferlist
> attrs
;
203 bool partial_content
;
206 bool skip_decrypt
{false};
208 utime_t gc_invalidate_time
;
211 bool rgwx_stat
; /* extended rgw stat operation */
215 RGWCompressionInfo cs_info
;
216 off_t first_block
, last_block
;
240 partial_content
= false;
241 range_parsed
= false;
242 skip_manifest
= false;
252 bool prefetch_data() override
;
254 void set_get_data(bool get_data
) {
255 this->get_data
= get_data
;
257 int verify_permission() override
;
258 void pre_exec() override
;
259 void execute() override
;
260 int read_user_manifest_part(
262 const rgw_bucket_dir_entry
& ent
,
263 RGWAccessControlPolicy
* const bucket_acl
,
264 const boost::optional
<rgw::IAM::Policy
>& bucket_policy
,
265 const off_t start_ofs
,
266 const off_t end_ofs
);
267 int handle_user_manifest(const char *prefix
);
268 int handle_slo_manifest(bufferlist
& bl
);
270 int get_data_cb(bufferlist
& bl
, off_t ofs
, off_t len
);
272 virtual int get_params() = 0;
273 virtual int send_response_data_error() = 0;
274 virtual int send_response_data(bufferlist
& bl
, off_t ofs
, off_t len
) = 0;
276 const string
name() override
{ return "get_obj"; }
277 RGWOpType
get_type() override
{ return RGW_OP_GET_OBJ
; }
278 uint32_t op_mask() override
{ return RGW_OP_TYPE_READ
; }
279 virtual bool need_object_expiration() { return false; }
281 * calculates filter used to decrypt RGW objects data
283 virtual int get_decrypt_filter(std::unique_ptr
<RGWGetDataCB
>* filter
, RGWGetDataCB
* cb
, bufferlist
* manifest_bl
) {
289 class RGWGetObj_CB
: public RGWGetDataCB
293 explicit RGWGetObj_CB(RGWGetObj
*_op
) : op(_op
) {}
294 ~RGWGetObj_CB() override
{}
296 int handle_data(bufferlist
& bl
, off_t bl_ofs
, off_t bl_len
) override
{
297 return op
->get_data_cb(bl
, bl_ofs
, bl_len
);
301 class RGWGetObj_Filter
: public RGWGetDataCB
306 RGWGetObj_Filter(RGWGetDataCB
* next
): next(next
) {}
307 ~RGWGetObj_Filter() override
{}
309 * Passes data through filter.
310 * Filter can modify content of bl.
311 * When bl_len == 0 , it means 'flush
313 int handle_data(bufferlist
& bl
, off_t bl_ofs
, off_t bl_len
) override
{
314 return next
->handle_data(bl
, bl_ofs
, bl_len
);
317 * Flushes any cached data. Used by RGWGetObjFilter.
318 * Return logic same as handle_data.
320 int flush() override
{
321 return next
->flush();
324 * Allows filter to extend range required for successful filtering
326 int fixup_range(off_t
& ofs
, off_t
& end
) override
{
327 return next
->fixup_range(ofs
, end
);
331 class RGWGetObjTags
: public RGWOp
{
334 bool has_tags
{false};
336 int verify_permission();
340 virtual void send_response_data(bufferlist
& bl
) = 0;
341 virtual const string
name() noexcept override
{ return "get_obj_tags"; }
342 virtual uint32_t op_mask() { return RGW_OP_TYPE_READ
; }
343 RGWOpType
get_type() { return RGW_OP_GET_OBJ_TAGGING
; }
347 class RGWPutObjTags
: public RGWOp
{
351 int verify_permission();
354 virtual void send_response() = 0;
355 virtual int get_params() = 0;
356 virtual const string
name() { return "put_obj_tags"; }
357 virtual uint32_t op_mask() { return RGW_OP_TYPE_WRITE
; }
358 RGWOpType
get_type() { return RGW_OP_PUT_OBJ_TAGGING
; }
362 class RGWDeleteObjTags
: public RGWOp
{
365 int verify_permission();
368 virtual void send_response() = 0;
369 virtual const string
name() { return "delete_obj_tags"; }
370 virtual uint32_t op_mask() { return RGW_OP_TYPE_DELETE
; }
371 RGWOpType
get_type() { return RGW_OP_DELETE_OBJ_TAGGING
;}
374 class RGWBulkDelete
: public RGWOp
{
377 std::string bucket_name
;
388 unsigned int num_deleted
;
389 unsigned int num_unfound
;
390 std::list
<fail_desc_t
> failures
;
392 RGWRados
* const store
;
396 Deleter(RGWRados
* const str
, req_state
* const s
)
403 unsigned int get_num_deleted() const {
407 unsigned int get_num_unfound() const {
411 const std::list
<fail_desc_t
> get_failures() const {
415 bool verify_permission(RGWBucketInfo
& binfo
,
416 map
<string
, bufferlist
>& battrs
,
417 ACLOwner
& bucket_owner
/* out */);
418 bool delete_single(const acct_path_t
& path
);
419 bool delete_chunk(const std::list
<acct_path_t
>& paths
);
421 /* End of Deleter subclass */
423 static const size_t MAX_CHUNK_ENTRIES
= 1024;
426 std::unique_ptr
<Deleter
> deleter
;
433 int verify_permission() override
;
434 void pre_exec() override
;
435 void execute() override
;
437 virtual int get_data(std::list
<acct_path_t
>& items
,
438 bool * is_truncated
) = 0;
439 void send_response() override
= 0;
441 const string
name() override
{ return "bulk_delete"; }
442 RGWOpType
get_type() override
{ return RGW_OP_BULK_DELETE
; }
443 uint32_t op_mask() override
{ return RGW_OP_TYPE_DELETE
; }
446 inline ostream
& operator<<(ostream
& out
, const RGWBulkDelete::acct_path_t
&o
) {
447 return out
<< o
.bucket_name
<< "/" << o
.obj_key
;
451 class RGWBulkUploadOp
: public RGWOp
{
452 boost::optional
<RGWObjectCtx
> dir_ctx
;
457 fail_desc_t(const int err
, std::string path
)
459 path(std::move(path
)) {
463 const std::string path
;
466 static constexpr std::array
<int, 2> terminal_errors
= {
470 /* FIXME: boost::container::small_vector<fail_desc_t, 4> failures; */
471 std::vector
<fail_desc_t
> failures
;
475 class DecoratedStreamGetter
;
476 class AlignedStreamGetter
;
478 virtual std::unique_ptr
<StreamGetter
> create_stream() = 0;
479 virtual void send_response() = 0;
481 boost::optional
<std::pair
<std::string
, rgw_obj_key
>>
482 parse_path(const boost::string_ref
& path
);
484 std::pair
<std::string
, std::string
>
485 handle_upload_path(struct req_state
*s
);
487 bool handle_file_verify_permission(RGWBucketInfo
& binfo
,
489 std::map
<std::string
, ceph::bufferlist
>& battrs
,
490 ACLOwner
& bucket_owner
/* out */);
491 int handle_file(boost::string_ref path
,
493 AlignedStreamGetter
& body
);
495 int handle_dir_verify_permission();
496 int handle_dir(boost::string_ref path
);
503 void init(RGWRados
* const store
,
504 struct req_state
* const s
,
505 RGWHandler
* const h
) override
{
506 RGWOp::init(store
, s
, h
);
507 dir_ctx
.emplace(store
);
510 int verify_permission() override
;
511 void pre_exec() override
;
512 void execute() override
;
514 const std::string
name() override
{
515 return "bulk_upload";
518 RGWOpType
get_type() override
{
519 return RGW_OP_BULK_UPLOAD
;
522 uint32_t op_mask() override
{
523 return RGW_OP_TYPE_WRITE
;
525 }; /* RGWBulkUploadOp */
528 class RGWBulkUploadOp::StreamGetter
{
530 StreamGetter() = default;
531 virtual ~StreamGetter() = default;
533 virtual ssize_t
get_at_most(size_t want
, ceph::bufferlist
& dst
) = 0;
534 virtual ssize_t
get_exactly(size_t want
, ceph::bufferlist
& dst
) = 0;
535 }; /* End of nested subclass StreamGetter */
538 class RGWBulkUploadOp::DecoratedStreamGetter
: public StreamGetter
{
539 StreamGetter
& decoratee
;
542 StreamGetter
& get_decoratee() {
547 DecoratedStreamGetter(StreamGetter
& decoratee
)
548 : decoratee(decoratee
) {
550 virtual ~DecoratedStreamGetter() = default;
552 ssize_t
get_at_most(const size_t want
, ceph::bufferlist
& dst
) override
{
553 return get_decoratee().get_at_most(want
, dst
);
556 ssize_t
get_exactly(const size_t want
, ceph::bufferlist
& dst
) override
{
557 return get_decoratee().get_exactly(want
, dst
);
559 }; /* RGWBulkUploadOp::DecoratedStreamGetter */
562 class RGWBulkUploadOp::AlignedStreamGetter
563 : public RGWBulkUploadOp::DecoratedStreamGetter
{
569 template <typename U
>
570 AlignedStreamGetter(const size_t position
,
572 const size_t alignment
,
574 : DecoratedStreamGetter(std::forward
<U
>(decoratee
)),
577 alignment(alignment
) {
579 virtual ~AlignedStreamGetter();
580 ssize_t
get_at_most(size_t want
, ceph::bufferlist
& dst
) override
;
581 ssize_t
get_exactly(size_t want
, ceph::bufferlist
& dst
) override
;
582 }; /* RGWBulkUploadOp::AlignedStreamGetter */
585 #define RGW_LIST_BUCKETS_LIMIT_MAX 10000
587 class RGWListBuckets
: public RGWOp
{
594 uint32_t buckets_count
;
595 uint64_t buckets_objcount
;
596 uint64_t buckets_size
;
597 uint64_t buckets_size_rounded
;
598 map
<string
, bufferlist
> attrs
;
601 virtual uint64_t get_default_max() const {
606 RGWListBuckets() : sent_data(false) {
607 limit
= limit_max
= RGW_LIST_BUCKETS_LIMIT_MAX
;
609 buckets_objcount
= 0;
611 buckets_size_rounded
= 0;
612 is_truncated
= false;
615 int verify_permission() override
;
616 void execute() override
;
618 virtual int get_params() = 0;
619 virtual void send_response_begin(bool has_buckets
) = 0;
620 virtual void send_response_data(RGWUserBuckets
& buckets
) = 0;
621 virtual void send_response_end() = 0;
622 void send_response() override
{}
624 virtual bool should_get_stats() { return false; }
625 virtual bool supports_account_metadata() { return false; }
627 const string
name() override
{ return "list_buckets"; }
628 RGWOpType
get_type() override
{ return RGW_OP_LIST_BUCKETS
; }
629 uint32_t op_mask() override
{ return RGW_OP_TYPE_READ
; }
632 class RGWGetUsage
: public RGWOp
{
637 int show_log_entries
;
639 map
<string
, bool> categories
;
640 map
<rgw_user_bucket
, rgw_usage_log_entry
> usage
;
641 map
<string
, rgw_usage_log_entry
> summary_map
;
642 map
<string
, cls_user_bucket_entry
> buckets_usage
;
643 cls_user_header header
;
645 RGWGetUsage() : sent_data(false), show_log_entries(true), show_log_sum(true){
648 int verify_permission() override
;
649 void execute() override
;
651 virtual int get_params() = 0;
652 void send_response() override
{}
654 virtual bool should_get_stats() { return false; }
656 const string
name() override
{ return "get_usage"; }
657 uint32_t op_mask() override
{ return RGW_OP_TYPE_READ
; }
660 class RGWStatAccount
: public RGWOp
{
662 uint32_t buckets_count
;
663 uint64_t buckets_objcount
;
664 uint64_t buckets_size
;
665 uint64_t buckets_size_rounded
;
670 buckets_objcount
= 0;
672 buckets_size_rounded
= 0;
675 int verify_permission() override
;
676 void execute() override
;
678 void send_response() override
= 0;
679 const string
name() override
{ return "stat_account"; }
680 RGWOpType
get_type() override
{ return RGW_OP_STAT_ACCOUNT
; }
681 uint32_t op_mask() override
{ return RGW_OP_TYPE_READ
; }
684 class RGWListBucket
: public RGWOp
{
689 rgw_obj_key next_marker
;
690 rgw_obj_key end_marker
;
693 string encoding_type
;
696 vector
<rgw_bucket_dir_entry
> objs
;
697 map
<string
, bool> common_prefixes
;
704 int parse_max_keys();
707 RGWListBucket() : list_versions(false), max(0),
708 default_max(0), is_truncated(false), shard_id(-1) {}
709 int verify_permission() override
;
710 void pre_exec() override
;
711 void execute() override
;
713 virtual int get_params() = 0;
714 void send_response() override
= 0;
715 const string
name() override
{ return "list_bucket"; }
716 RGWOpType
get_type() override
{ return RGW_OP_LIST_BUCKET
; }
717 uint32_t op_mask() override
{ return RGW_OP_TYPE_READ
; }
718 virtual bool need_container_stats() { return false; }
721 class RGWGetBucketLogging
: public RGWOp
{
723 RGWGetBucketLogging() {}
724 int verify_permission() override
;
725 void execute() override
{ }
727 void send_response() override
= 0;
728 const string
name() override
{ return "get_bucket_logging"; }
729 RGWOpType
get_type() override
{ return RGW_OP_GET_BUCKET_LOGGING
; }
730 uint32_t op_mask() override
{ return RGW_OP_TYPE_READ
; }
733 class RGWGetBucketLocation
: public RGWOp
{
735 RGWGetBucketLocation() {}
736 ~RGWGetBucketLocation() override
{}
737 int verify_permission() override
;
738 void execute() override
{ }
740 void send_response() override
= 0;
741 const string
name() override
{ return "get_bucket_location"; }
742 uint32_t op_mask() override
{ return RGW_OP_TYPE_READ
; }
745 class RGWGetBucketVersioning
: public RGWOp
{
748 bool versioning_enabled
;
750 RGWGetBucketVersioning() : versioned(false), versioning_enabled(false) {}
752 int verify_permission() override
;
753 void pre_exec() override
;
754 void execute() override
;
756 void send_response() override
= 0;
757 const string
name() override
{ return "get_bucket_versioning"; }
758 RGWOpType
get_type() override
{ return RGW_OP_GET_BUCKET_VERSIONING
; }
759 uint32_t op_mask() override
{ return RGW_OP_TYPE_READ
; }
762 class RGWSetBucketVersioning
: public RGWOp
{
764 bool enable_versioning
;
767 RGWSetBucketVersioning() : enable_versioning(false) {}
769 int verify_permission() override
;
770 void pre_exec() override
;
771 void execute() override
;
773 virtual int get_params() { return 0; }
775 void send_response() override
= 0;
776 const string
name() override
{ return "set_bucket_versioning"; }
777 RGWOpType
get_type() override
{ return RGW_OP_SET_BUCKET_VERSIONING
; }
778 uint32_t op_mask() override
{ return RGW_OP_TYPE_WRITE
; }
781 class RGWGetBucketWebsite
: public RGWOp
{
783 RGWGetBucketWebsite() {}
785 int verify_permission() override
;
786 void pre_exec() override
;
787 void execute() override
;
789 void send_response() override
= 0;
790 const string
name() override
{ return "get_bucket_website"; }
791 RGWOpType
get_type() override
{ return RGW_OP_GET_BUCKET_WEBSITE
; }
792 uint32_t op_mask() override
{ return RGW_OP_TYPE_READ
; }
795 class RGWSetBucketWebsite
: public RGWOp
{
798 RGWBucketWebsiteConf website_conf
;
800 RGWSetBucketWebsite() {}
802 int verify_permission() override
;
803 void pre_exec() override
;
804 void execute() override
;
806 virtual int get_params() { return 0; }
808 void send_response() override
= 0;
809 const string
name() override
{ return "set_bucket_website"; }
810 RGWOpType
get_type() override
{ return RGW_OP_SET_BUCKET_WEBSITE
; }
811 uint32_t op_mask() override
{ return RGW_OP_TYPE_WRITE
; }
814 class RGWDeleteBucketWebsite
: public RGWOp
{
816 RGWDeleteBucketWebsite() {}
818 int verify_permission() override
;
819 void pre_exec() override
;
820 void execute() override
;
822 void send_response() override
= 0;
823 const string
name() override
{ return "delete_bucket_website"; }
824 RGWOpType
get_type() override
{ return RGW_OP_SET_BUCKET_WEBSITE
; }
825 uint32_t op_mask() override
{ return RGW_OP_TYPE_WRITE
; }
828 class RGWStatBucket
: public RGWOp
{
834 ~RGWStatBucket() override
{}
836 int verify_permission() override
;
837 void pre_exec() override
;
838 void execute() override
;
840 void send_response() override
= 0;
841 const string
name() override
{ return "stat_bucket"; }
842 RGWOpType
get_type() override
{ return RGW_OP_STAT_BUCKET
; }
843 uint32_t op_mask() override
{ return RGW_OP_TYPE_READ
; }
846 class RGWCreateBucket
: public RGWOp
{
848 RGWAccessControlPolicy policy
;
849 string location_constraint
;
850 string placement_rule
;
854 RGWCORSConfiguration cors_config
;
855 boost::optional
<std::string
> swift_ver_location
;
856 map
<string
, buffer::list
> attrs
;
857 set
<string
> rmattr_names
;
861 virtual bool need_metadata_upload() const { return false; }
864 RGWCreateBucket() : has_cors(false) {}
866 void emplace_attr(std::string
&& key
, buffer::list
&& bl
) {
867 attrs
.emplace(std::move(key
), std::move(bl
)); /* key and bl are r-value refs */
870 int verify_permission() override
;
871 void pre_exec() override
;
872 void execute() override
;
873 void init(RGWRados
*store
, struct req_state
*s
, RGWHandler
*h
) override
{
874 RGWOp::init(store
, s
, h
);
875 policy
.set_ctx(s
->cct
);
877 virtual int get_params() { return 0; }
878 void send_response() override
= 0;
879 const string
name() override
{ return "create_bucket"; }
880 RGWOpType
get_type() override
{ return RGW_OP_CREATE_BUCKET
; }
881 uint32_t op_mask() override
{ return RGW_OP_TYPE_WRITE
; }
884 class RGWDeleteBucket
: public RGWOp
{
886 RGWObjVersionTracker objv_tracker
;
891 int verify_permission() override
;
892 void pre_exec() override
;
893 void execute() override
;
895 void send_response() override
= 0;
896 const string
name() override
{ return "delete_bucket"; }
897 RGWOpType
get_type() override
{ return RGW_OP_DELETE_BUCKET
; }
898 uint32_t op_mask() override
{ return RGW_OP_TYPE_DELETE
; }
901 struct rgw_slo_entry
{
906 rgw_slo_entry() : size_bytes(0) {}
908 void encode(bufferlist
& bl
) const {
909 ENCODE_START(1, 1, bl
);
912 ::encode(size_bytes
, bl
);
916 void decode(bufferlist::iterator
& bl
) {
920 ::decode(size_bytes
, bl
);
924 void decode_json(JSONObj
*obj
);
926 WRITE_CLASS_ENCODER(rgw_slo_entry
)
929 vector
<rgw_slo_entry
> entries
;
936 RGWSLOInfo() : total_size(0), raw_data(NULL
), raw_data_len(0) {}
941 void encode(bufferlist
& bl
) const {
942 ENCODE_START(1, 1, bl
);
943 ::encode(entries
, bl
);
944 ::encode(total_size
, bl
);
948 void decode(bufferlist::iterator
& bl
) {
950 ::decode(entries
, bl
);
951 ::decode(total_size
, bl
);
955 WRITE_CLASS_ENCODER(RGWSLOInfo
)
957 class RGWPutObj
: public RGWOp
{
959 friend class RGWPutObjProcessor
;
964 const char *supplied_md5_b64
;
965 const char *supplied_etag
;
966 const char *if_match
;
967 const char *if_nomatch
;
968 const char *copy_source
;
969 const char *copy_source_range
;
970 RGWBucketInfo copy_source_bucket_info
;
971 string copy_source_tenant_name
;
972 string copy_source_bucket_name
;
973 string copy_source_object_name
;
974 string copy_source_version_id
;
975 off_t copy_source_range_fst
;
976 off_t copy_source_range_lst
;
979 RGWAccessControlPolicy policy
;
980 std::unique_ptr
<RGWObjTags
> obj_tags
;
981 const char *dlo_manifest
;
982 RGWSLOInfo
*slo_info
;
983 map
<string
, bufferlist
> attrs
;
984 ceph::real_time mtime
;
988 map
<string
, string
> crypt_http_responses
;
991 boost::optional
<ceph::real_time
> delete_at
;
994 RGWPutObj() : ofs(0),
995 supplied_md5_b64(NULL
),
1000 copy_source_range(NULL
),
1001 copy_source_range_fst(0),
1002 copy_source_range_lst(0),
1008 ~RGWPutObj() override
{
1012 void init(RGWRados
*store
, struct req_state
*s
, RGWHandler
*h
) override
{
1013 RGWOp::init(store
, s
, h
);
1014 policy
.set_ctx(s
->cct
);
1017 void emplace_attr(std::string
&& key
, buffer::list
&& bl
) {
1018 attrs
.emplace(std::move(key
), std::move(bl
)); /* key and bl are r-value refs */
1021 virtual RGWPutObjProcessor
*select_processor(RGWObjectCtx
& obj_ctx
, bool *is_multipart
);
1022 void dispose_processor(RGWPutObjDataProcessor
*processor
);
1024 int verify_permission() override
;
1025 void pre_exec() override
;
1026 void execute() override
;
1028 /* this is for cases when copying data from other object */
1029 virtual int get_decrypt_filter(std::unique_ptr
<RGWGetDataCB
>* filter
,
1031 map
<string
, bufferlist
>& attrs
,
1032 bufferlist
* manifest_bl
) {
1036 virtual int get_encrypt_filter(std::unique_ptr
<RGWPutObjDataProcessor
> *filter
, RGWPutObjDataProcessor
* cb
) {
1041 int get_data_cb(bufferlist
& bl
, off_t bl_ofs
, off_t bl_len
);
1042 int get_data(const off_t fst
, const off_t lst
, bufferlist
& bl
);
1044 virtual int get_params() = 0;
1045 virtual int get_data(bufferlist
& bl
) = 0;
1046 void send_response() override
= 0;
1047 const string
name() override
{ return "put_obj"; }
1048 RGWOpType
get_type() override
{ return RGW_OP_PUT_OBJ
; }
1049 uint32_t op_mask() override
{ return RGW_OP_TYPE_WRITE
; }
1052 class RGWPutObj_Filter
: public RGWPutObjDataProcessor
1055 RGWPutObjDataProcessor
* next
;
1057 RGWPutObj_Filter(RGWPutObjDataProcessor
* next
) :
1059 ~RGWPutObj_Filter() override
{}
1060 int handle_data(bufferlist
& bl
, off_t ofs
, void **phandle
, rgw_raw_obj
*pobj
, bool *again
) override
{
1061 return next
->handle_data(bl
, ofs
, phandle
, pobj
, again
);
1063 int throttle_data(void *handle
, const rgw_raw_obj
& obj
, uint64_t size
, bool need_to_wait
) override
{
1064 return next
->throttle_data(handle
, obj
, size
, need_to_wait
);
1066 }; /* RGWPutObj_Filter */
1068 class RGWPostObj
: public RGWOp
{
1074 const char *supplied_md5_b64
;
1075 const char *supplied_etag
;
1077 RGWAccessControlPolicy policy
;
1078 map
<string
, bufferlist
> attrs
;
1079 boost::optional
<ceph::real_time
> delete_at
;
1081 /* Must be called after get_data() or the result is undefined. */
1082 virtual std::string
get_current_filename() const = 0;
1083 virtual std::string
get_current_content_type() const = 0;
1084 virtual bool is_next_file_to_upload() {
1088 RGWPostObj() : min_len(0),
1092 supplied_md5_b64(nullptr),
1093 supplied_etag(nullptr) {
1096 void emplace_attr(std::string
&& key
, buffer::list
&& bl
) {
1097 attrs
.emplace(std::move(key
), std::move(bl
)); /* key and bl are r-value refs */
1100 void init(RGWRados
*store
, struct req_state
*s
, RGWHandler
*h
) override
{
1101 RGWOp::init(store
, s
, h
);
1102 policy
.set_ctx(s
->cct
);
1105 int verify_permission() override
;
1106 void pre_exec() override
;
1107 void execute() override
;
1109 virtual int get_encrypt_filter(std::unique_ptr
<RGWPutObjDataProcessor
> *filter
, RGWPutObjDataProcessor
* cb
) {
1113 virtual int get_params() = 0;
1114 virtual int get_data(ceph::bufferlist
& bl
, bool& again
) = 0;
1115 void send_response() override
= 0;
1116 const std::string
name() override
{ return "post_obj"; }
1117 RGWOpType
get_type() override
{ return RGW_OP_POST_OBJ
; }
1118 uint32_t op_mask() override
{ return RGW_OP_TYPE_WRITE
; }
1121 class RGWPutMetadataAccount
: public RGWOp
{
1123 std::set
<std::string
> rmattr_names
;
1124 std::map
<std::string
, bufferlist
> attrs
, orig_attrs
;
1125 std::map
<int, std::string
> temp_url_keys
;
1126 RGWQuotaInfo new_quota
;
1127 bool new_quota_extracted
;
1129 RGWObjVersionTracker acct_op_tracker
;
1131 RGWAccessControlPolicy policy
;
1135 RGWPutMetadataAccount()
1136 : new_quota_extracted(false),
1140 void init(RGWRados
*store
, struct req_state
*s
, RGWHandler
*h
) override
{
1141 RGWOp::init(store
, s
, h
);
1142 policy
.set_ctx(s
->cct
);
1144 int init_processing() override
;
1145 int verify_permission() override
;
1146 void pre_exec() override
{ }
1147 void execute() override
;
1149 virtual int get_params() = 0;
1150 void send_response() override
= 0;
1151 virtual void filter_out_temp_url(map
<string
, bufferlist
>& add_attrs
,
1152 const set
<string
>& rmattr_names
,
1153 map
<int, string
>& temp_url_keys
);
1154 const string
name() override
{ return "put_account_metadata"; }
1155 RGWOpType
get_type() override
{ return RGW_OP_PUT_METADATA_ACCOUNT
; }
1156 uint32_t op_mask() override
{ return RGW_OP_TYPE_WRITE
; }
1159 class RGWPutMetadataBucket
: public RGWOp
{
1161 map
<string
, buffer::list
> attrs
;
1162 set
<string
> rmattr_names
;
1163 bool has_policy
, has_cors
;
1164 uint32_t policy_rw_mask
;
1165 RGWAccessControlPolicy policy
;
1166 RGWCORSConfiguration cors_config
;
1167 string placement_rule
;
1168 boost::optional
<std::string
> swift_ver_location
;
1171 RGWPutMetadataBucket()
1172 : has_policy(false), has_cors(false), policy_rw_mask(0)
1175 void emplace_attr(std::string
&& key
, buffer::list
&& bl
) {
1176 attrs
.emplace(std::move(key
), std::move(bl
)); /* key and bl are r-value refs */
1179 void init(RGWRados
*store
, struct req_state
*s
, RGWHandler
*h
) override
{
1180 RGWOp::init(store
, s
, h
);
1181 policy
.set_ctx(s
->cct
);
1184 int verify_permission() override
;
1185 void pre_exec() override
;
1186 void execute() override
;
1188 virtual int get_params() = 0;
1189 void send_response() override
= 0;
1190 const string
name() override
{ return "put_bucket_metadata"; }
1191 RGWOpType
get_type() override
{ return RGW_OP_PUT_METADATA_BUCKET
; }
1192 uint32_t op_mask() override
{ return RGW_OP_TYPE_WRITE
; }
1195 class RGWPutMetadataObject
: public RGWOp
{
1197 RGWAccessControlPolicy policy
;
1198 string placement_rule
;
1199 boost::optional
<ceph::real_time
> delete_at
;
1200 const char *dlo_manifest
;
1203 RGWPutMetadataObject()
1204 : dlo_manifest(NULL
)
1207 void init(RGWRados
*store
, struct req_state
*s
, RGWHandler
*h
) override
{
1208 RGWOp::init(store
, s
, h
);
1209 policy
.set_ctx(s
->cct
);
1211 int verify_permission() override
;
1212 void pre_exec() override
;
1213 void execute() override
;
1215 virtual int get_params() = 0;
1216 void send_response() override
= 0;
1217 const string
name() override
{ return "put_obj_metadata"; }
1218 RGWOpType
get_type() override
{ return RGW_OP_PUT_METADATA_OBJECT
; }
1219 uint32_t op_mask() override
{ return RGW_OP_TYPE_WRITE
; }
1220 virtual bool need_object_expiration() { return false; }
1223 class RGWDeleteObj
: public RGWOp
{
1226 bool multipart_delete
;
1228 ceph::real_time unmod_since
; /* if unmodified since */
1229 bool no_precondition_error
;
1230 std::unique_ptr
<RGWBulkDelete::Deleter
> deleter
;
1234 : delete_marker(false),
1235 multipart_delete(false),
1236 no_precondition_error(false),
1240 int verify_permission() override
;
1241 void pre_exec() override
;
1242 void execute() override
;
1243 int handle_slo_manifest(bufferlist
& bl
);
1245 virtual int get_params() { return 0; }
1246 void send_response() override
= 0;
1247 const string
name() override
{ return "delete_obj"; }
1248 RGWOpType
get_type() override
{ return RGW_OP_DELETE_OBJ
; }
1249 uint32_t op_mask() override
{ return RGW_OP_TYPE_DELETE
; }
1250 virtual bool need_object_expiration() { return false; }
1253 class RGWCopyObj
: public RGWOp
{
1255 RGWAccessControlPolicy dest_policy
;
1257 const char *if_unmod
;
1258 const char *if_match
;
1259 const char *if_nomatch
;
1263 ceph::real_time mod_time
;
1264 ceph::real_time unmod_time
;
1265 ceph::real_time
*mod_ptr
;
1266 ceph::real_time
*unmod_ptr
;
1267 map
<string
, buffer::list
> attrs
;
1268 string src_tenant_name
, src_bucket_name
;
1269 rgw_bucket src_bucket
;
1270 rgw_obj_key src_object
;
1271 string dest_tenant_name
, dest_bucket_name
;
1272 rgw_bucket dest_bucket
;
1274 ceph::real_time src_mtime
;
1275 ceph::real_time mtime
;
1276 RGWRados::AttrsMod attrs_mod
;
1277 RGWBucketInfo src_bucket_info
;
1278 RGWBucketInfo dest_bucket_info
;
1282 ceph::buffer::list etag
;
1289 boost::optional
<ceph::real_time
> delete_at
;
1305 attrs_mod
= RGWRados::ATTRSMOD_NONE
;
1308 copy_if_newer
= false;
1311 static bool parse_copy_location(const string
& src
,
1312 string
& bucket_name
,
1313 rgw_obj_key
& object
);
1315 void emplace_attr(std::string
&& key
, buffer::list
&& bl
) {
1316 attrs
.emplace(std::move(key
), std::move(bl
));
1319 void init(RGWRados
*store
, struct req_state
*s
, RGWHandler
*h
) override
{
1320 RGWOp::init(store
, s
, h
);
1321 dest_policy
.set_ctx(s
->cct
);
1323 int verify_permission() override
;
1324 void pre_exec() override
;
1325 void execute() override
;
1326 void progress_cb(off_t ofs
);
1328 virtual int init_dest_policy() { return 0; }
1329 virtual int get_params() = 0;
1330 virtual void send_partial_response(off_t ofs
) {}
1331 void send_response() override
= 0;
1332 const string
name() override
{ return "copy_obj"; }
1333 RGWOpType
get_type() override
{ return RGW_OP_COPY_OBJ
; }
1334 uint32_t op_mask() override
{ return RGW_OP_TYPE_WRITE
; }
1337 class RGWGetACLs
: public RGWOp
{
1344 int verify_permission() override
;
1345 void pre_exec() override
;
1346 void execute() override
;
1348 void send_response() override
= 0;
1349 const string
name() override
{ return "get_acls"; }
1350 RGWOpType
get_type() override
{ return RGW_OP_GET_ACLS
; }
1351 uint32_t op_mask() override
{ return RGW_OP_TYPE_READ
; }
1354 class RGWPutACLs
: public RGWOp
{
1365 ~RGWPutACLs() override
{
1369 int verify_permission() override
;
1370 void pre_exec() override
;
1371 void execute() override
;
1373 virtual int get_policy_from_state(RGWRados
*store
, struct req_state
*s
, stringstream
& ss
) { return 0; }
1374 virtual int get_params() = 0;
1375 void send_response() override
= 0;
1376 const string
name() override
{ return "put_acls"; }
1377 RGWOpType
get_type() override
{ return RGW_OP_PUT_ACLS
; }
1378 uint32_t op_mask() override
{ return RGW_OP_TYPE_WRITE
; }
1381 class RGWGetLC
: public RGWOp
{
1386 ~RGWGetLC() override
{ }
1388 int verify_permission() override
;
1389 void pre_exec() override
;
1390 void execute() override
= 0;
1392 void send_response() override
= 0;
1393 const string
name() override
{ return "get_lifecycle"; }
1394 RGWOpType
get_type() override
{ return RGW_OP_GET_LC
; }
1395 uint32_t op_mask() override
{ return RGW_OP_TYPE_READ
; }
1398 class RGWPutLC
: public RGWOp
{
1409 ~RGWPutLC() override
{
1413 void init(RGWRados
*store
, struct req_state
*s
, RGWHandler
*dialect_handler
) override
{
1414 #define COOKIE_LEN 16
1415 char buf
[COOKIE_LEN
+ 1];
1417 RGWOp::init(store
, s
, dialect_handler
);
1418 gen_rand_alphanumeric(s
->cct
, buf
, sizeof(buf
) - 1);
1422 int verify_permission() override
;
1423 void pre_exec() override
;
1424 void execute() override
;
1426 // virtual int get_policy_from_state(RGWRados *store, struct req_state *s, stringstream& ss) { return 0; }
1427 virtual int get_params() = 0;
1428 void send_response() override
= 0;
1429 const string
name() override
{ return "put_lifecycle"; }
1430 RGWOpType
get_type() override
{ return RGW_OP_PUT_LC
; }
1431 uint32_t op_mask() override
{ return RGW_OP_TYPE_WRITE
; }
1434 class RGWDeleteLC
: public RGWOp
{
1444 ~RGWDeleteLC() override
{
1448 int verify_permission() override
;
1449 void pre_exec() override
;
1450 void execute() override
;
1452 void send_response() override
= 0;
1453 const string
name() override
{ return "delete_lifecycle"; }
1454 RGWOpType
get_type() override
{ return RGW_OP_DELETE_LC
; }
1455 uint32_t op_mask() override
{ return RGW_OP_TYPE_WRITE
; }
1458 class RGWGetCORS
: public RGWOp
{
1464 int verify_permission() override
;
1465 void execute() override
;
1467 void send_response() override
= 0;
1468 const string
name() override
{ return "get_cors"; }
1469 RGWOpType
get_type() override
{ return RGW_OP_GET_CORS
; }
1470 uint32_t op_mask() override
{ return RGW_OP_TYPE_READ
; }
1473 class RGWPutCORS
: public RGWOp
{
1480 ~RGWPutCORS() override
{}
1482 int verify_permission() override
;
1483 void execute() override
;
1485 virtual int get_params() = 0;
1486 void send_response() override
= 0;
1487 const string
name() override
{ return "put_cors"; }
1488 RGWOpType
get_type() override
{ return RGW_OP_PUT_CORS
; }
1489 uint32_t op_mask() override
{ return RGW_OP_TYPE_WRITE
; }
1492 class RGWDeleteCORS
: public RGWOp
{
1498 int verify_permission() override
;
1499 void execute() override
;
1501 void send_response() override
= 0;
1502 const string
name() override
{ return "delete_cors"; }
1503 RGWOpType
get_type() override
{ return RGW_OP_DELETE_CORS
; }
1504 uint32_t op_mask() override
{ return RGW_OP_TYPE_WRITE
; }
1507 class RGWOptionsCORS
: public RGWOp
{
1510 const char *origin
, *req_hdrs
, *req_meth
;
1513 RGWOptionsCORS() : rule(NULL
), origin(NULL
),
1514 req_hdrs(NULL
), req_meth(NULL
) {
1517 int verify_permission() override
{return 0;}
1518 int validate_cors_request(RGWCORSConfiguration
*cc
);
1519 void execute() override
;
1520 void get_response_params(string
& allowed_hdrs
, string
& exp_hdrs
, unsigned *max_age
);
1521 void send_response() override
= 0;
1522 const string
name() override
{ return "options_cors"; }
1523 RGWOpType
get_type() override
{ return RGW_OP_OPTIONS_CORS
; }
1524 uint32_t op_mask() override
{ return RGW_OP_TYPE_READ
; }
1527 class RGWGetRequestPayment
: public RGWOp
{
1529 bool requester_pays
;
1532 RGWGetRequestPayment() : requester_pays(0) {}
1534 int verify_permission() override
;
1535 void pre_exec() override
;
1536 void execute() override
;
1538 void send_response() override
= 0;
1539 const string
name() override
{ return "get_request_payment"; }
1540 RGWOpType
get_type() override
{ return RGW_OP_GET_REQUEST_PAYMENT
; }
1541 uint32_t op_mask() override
{ return RGW_OP_TYPE_READ
; }
1544 class RGWSetRequestPayment
: public RGWOp
{
1546 bool requester_pays
;
1548 RGWSetRequestPayment() : requester_pays(false) {}
1550 int verify_permission() override
;
1551 void pre_exec() override
;
1552 void execute() override
;
1554 virtual int get_params() { return 0; }
1556 void send_response() override
= 0;
1557 const string
name() override
{ return "set_request_payment"; }
1558 RGWOpType
get_type() override
{ return RGW_OP_SET_REQUEST_PAYMENT
; }
1559 uint32_t op_mask() override
{ return RGW_OP_TYPE_WRITE
; }
1562 class RGWInitMultipart
: public RGWOp
{
1565 RGWAccessControlPolicy policy
;
1568 RGWInitMultipart() {}
1570 void init(RGWRados
*store
, struct req_state
*s
, RGWHandler
*h
) override
{
1571 RGWOp::init(store
, s
, h
);
1572 policy
.set_ctx(s
->cct
);
1574 int verify_permission() override
;
1575 void pre_exec() override
;
1576 void execute() override
;
1578 virtual int get_params() = 0;
1579 void send_response() override
= 0;
1580 const string
name() override
{ return "init_multipart"; }
1581 RGWOpType
get_type() override
{ return RGW_OP_INIT_MULTIPART
; }
1582 uint32_t op_mask() override
{ return RGW_OP_TYPE_WRITE
; }
1583 virtual int prepare_encryption(map
<string
, bufferlist
>& attrs
) { return 0; }
1586 class RGWCompleteMultipart
: public RGWOp
{
1594 RGWCompleteMultipart() {
1598 ~RGWCompleteMultipart() override
{
1602 int verify_permission() override
;
1603 void pre_exec() override
;
1604 void execute() override
;
1606 virtual int get_params() = 0;
1607 void send_response() override
= 0;
1608 const string
name() override
{ return "complete_multipart"; }
1609 RGWOpType
get_type() override
{ return RGW_OP_COMPLETE_MULTIPART
; }
1610 uint32_t op_mask() override
{ return RGW_OP_TYPE_WRITE
; }
1613 class RGWAbortMultipart
: public RGWOp
{
1615 RGWAbortMultipart() {}
1617 int verify_permission() override
;
1618 void pre_exec() override
;
1619 void execute() override
;
1621 void send_response() override
= 0;
1622 const string
name() override
{ return "abort_multipart"; }
1623 RGWOpType
get_type() override
{ return RGW_OP_ABORT_MULTIPART
; }
1624 uint32_t op_mask() override
{ return RGW_OP_TYPE_DELETE
; }
1627 class RGWListMultipart
: public RGWOp
{
1630 map
<uint32_t, RGWUploadPartInfo
> parts
;
1633 RGWAccessControlPolicy policy
;
1637 RGWListMultipart() {
1643 void init(RGWRados
*store
, struct req_state
*s
, RGWHandler
*h
) override
{
1644 RGWOp::init(store
, s
, h
);
1645 policy
= RGWAccessControlPolicy(s
->cct
);
1647 int verify_permission() override
;
1648 void pre_exec() override
;
1649 void execute() override
;
1651 virtual int get_params() = 0;
1652 void send_response() override
= 0;
1653 const string
name() override
{ return "list_multipart"; }
1654 RGWOpType
get_type() override
{ return RGW_OP_LIST_MULTIPART
; }
1655 uint32_t op_mask() override
{ return RGW_OP_TYPE_READ
; }
1658 struct RGWMultipartUploadEntry
{
1659 rgw_bucket_dir_entry obj
;
1663 class RGWListBucketMultiparts
: public RGWOp
{
1667 RGWMultipartUploadEntry next_marker
;
1670 vector
<RGWMultipartUploadEntry
> uploads
;
1671 map
<string
, bool> common_prefixes
;
1676 RGWListBucketMultiparts() {
1678 is_truncated
= false;
1682 void init(RGWRados
*store
, struct req_state
*s
, RGWHandler
*h
) override
{
1683 RGWOp::init(store
, s
, h
);
1684 max_uploads
= default_max
;
1687 int verify_permission() override
;
1688 void pre_exec() override
;
1689 void execute() override
;
1691 virtual int get_params() = 0;
1692 void send_response() override
= 0;
1693 const string
name() override
{ return "list_bucket_multiparts"; }
1694 RGWOpType
get_type() override
{ return RGW_OP_LIST_BUCKET_MULTIPARTS
; }
1695 uint32_t op_mask() override
{ return RGW_OP_TYPE_READ
; }
1699 class RGWGetCrossDomainPolicy
: public RGWOp
{
1701 RGWGetCrossDomainPolicy() = default;
1702 ~RGWGetCrossDomainPolicy() override
= default;
1704 int verify_permission() override
{
1708 void execute() override
{
1712 const string
name() override
{
1713 return "get_crossdomain_policy";
1716 RGWOpType
get_type() override
{
1717 return RGW_OP_GET_CROSS_DOMAIN_POLICY
;
1720 uint32_t op_mask() override
{
1721 return RGW_OP_TYPE_READ
;
1726 class RGWGetHealthCheck
: public RGWOp
{
1728 RGWGetHealthCheck() = default;
1729 ~RGWGetHealthCheck() override
= default;
1731 int verify_permission() override
{
1735 void execute() override
;
1737 const string
name() override
{
1738 return "get_health_check";
1741 RGWOpType
get_type() override
{
1742 return RGW_OP_GET_HEALTH_CHECK
;
1745 uint32_t op_mask() override
{
1746 return RGW_OP_TYPE_READ
;
1751 class RGWDeleteMultiObj
: public RGWOp
{
1759 bool acl_allowed
= false;
1762 RGWDeleteMultiObj() {
1763 max_to_delete
= 1000;
1767 status_dumped
= false;
1769 int verify_permission() override
;
1770 void pre_exec() override
;
1771 void execute() override
;
1773 virtual int get_params() = 0;
1774 virtual void send_status() = 0;
1775 virtual void begin_response() = 0;
1776 virtual void send_partial_response(rgw_obj_key
& key
, bool delete_marker
,
1777 const string
& marker_version_id
, int ret
) = 0;
1778 virtual void end_response() = 0;
1779 const string
name() override
{ return "multi_object_delete"; }
1780 RGWOpType
get_type() override
{ return RGW_OP_DELETE_MULTI_OBJ
; }
1781 uint32_t op_mask() override
{ return RGW_OP_TYPE_DELETE
; }
1784 class RGWInfo
: public RGWOp
{
1786 RGWInfo() = default;
1787 ~RGWInfo() override
= default;
1789 int verify_permission() override
{ return 0; }
1790 const string
name() override
{ return "get info"; }
1791 RGWOpType
get_type() override
{ return RGW_OP_GET_INFO
; }
1792 uint32_t op_mask() override
{ return RGW_OP_TYPE_READ
; }
1795 extern int rgw_build_bucket_policies(RGWRados
* store
, struct req_state
* s
);
1796 extern int rgw_build_object_policies(RGWRados
*store
, struct req_state
*s
,
1797 bool prefetch_data
);
1798 extern rgw::IAM::Environment
rgw_build_iam_environment(RGWRados
* store
,
1799 struct req_state
* s
);
1801 static inline int put_data_and_throttle(RGWPutObjDataProcessor
*processor
,
1802 bufferlist
& data
, off_t ofs
,
1807 void *handle
= nullptr;
1810 uint64_t size
= data
.length();
1812 int ret
= processor
->handle_data(data
, ofs
, &handle
, &obj
, &again
);
1815 if (handle
!= nullptr)
1817 ret
= processor
->throttle_data(handle
, obj
, size
, need_to_wait
);
1823 need_to_wait
= false; /* the need to wait only applies to the first
1828 } /* put_data_and_throttle */
1834 static inline int get_system_versioning_params(req_state
*s
,
1835 uint64_t *olh_epoch
,
1838 if (!s
->system_request
) {
1843 string epoch_str
= s
->info
.args
.get(RGW_SYS_PARAM_PREFIX
"versioned-epoch");
1844 if (!epoch_str
.empty()) {
1846 *olh_epoch
= strict_strtol(epoch_str
.c_str(), 10, &err
);
1848 lsubdout(s
->cct
, rgw
, 0) << "failed to parse versioned-epoch param"
1856 *version_id
= s
->info
.args
.get(RGW_SYS_PARAM_PREFIX
"version-id");
1860 } /* get_system_versioning_params */
1862 static inline void format_xattr(std::string
&xattr
)
1864 /* If the extended attribute is not valid UTF-8, we encode it using
1865 * quoted-printable encoding.
1867 if ((check_utf8(xattr
.c_str(), xattr
.length()) != 0) ||
1868 (check_for_control_characters(xattr
.c_str(), xattr
.length()) != 0)) {
1869 static const char MIME_PREFIX_STR
[] = "=?UTF-8?Q?";
1870 static const int MIME_PREFIX_LEN
= sizeof(MIME_PREFIX_STR
) - 1;
1871 static const char MIME_SUFFIX_STR
[] = "?=";
1872 static const int MIME_SUFFIX_LEN
= sizeof(MIME_SUFFIX_STR
) - 1;
1873 int mlen
= mime_encode_as_qp(xattr
.c_str(), NULL
, 0);
1874 char *mime
= new char[MIME_PREFIX_LEN
+ mlen
+ MIME_SUFFIX_LEN
+ 1];
1875 strcpy(mime
, MIME_PREFIX_STR
);
1876 mime_encode_as_qp(xattr
.c_str(), mime
+ MIME_PREFIX_LEN
, mlen
);
1877 strcpy(mime
+ MIME_PREFIX_LEN
+ (mlen
- 1), MIME_SUFFIX_STR
);
1881 } /* format_xattr */
1884 * Get the HTTP request metadata out of the req_state as a
1885 * map(<attr_name, attr_contents>, where attr_name is RGW_ATTR_PREFIX.HTTP_NAME)
1886 * s: The request state
1887 * attrs: will be filled up with attrs mapped as <attr_name, attr_contents>
1890 static inline void rgw_get_request_metadata(CephContext
*cct
,
1891 struct req_info
& info
,
1892 map
<string
, bufferlist
>& attrs
,
1893 const bool allow_empty_attrs
= true)
1895 static const std::set
<std::string
> blacklisted_headers
= {
1896 "x-amz-server-side-encryption-customer-algorithm",
1897 "x-amz-server-side-encryption-customer-key",
1898 "x-amz-server-side-encryption-customer-key-md5"
1900 map
<string
, string
>::iterator iter
;
1901 for (iter
= info
.x_meta_map
.begin(); iter
!= info
.x_meta_map
.end(); ++iter
) {
1902 const string
&name(iter
->first
);
1903 string
&xattr(iter
->second
);
1904 if (blacklisted_headers
.count(name
) == 1) {
1905 lsubdout(cct
, rgw
, 10) << "skipping x>> " << name
<< dendl
;
1908 if (allow_empty_attrs
|| !xattr
.empty()) {
1909 lsubdout(cct
, rgw
, 10) << "x>> " << name
<< ":" << xattr
<< dendl
;
1910 format_xattr(xattr
);
1911 string
attr_name(RGW_ATTR_PREFIX
);
1912 attr_name
.append(name
);
1913 map
<string
, bufferlist
>::value_type
v(attr_name
, bufferlist());
1914 std::pair
< map
<string
, bufferlist
>::iterator
, bool >
1915 rval(attrs
.insert(v
));
1916 bufferlist
& bl(rval
.first
->second
);
1917 bl
.append(xattr
.c_str(), xattr
.size() + 1);
1920 } /* rgw_get_request_metadata */
1922 static inline void encode_delete_at_attr(boost::optional
<ceph::real_time
> delete_at
,
1923 map
<string
, bufferlist
>& attrs
)
1925 if (delete_at
== boost::none
) {
1930 ::encode(*delete_at
, delatbl
);
1931 attrs
[RGW_ATTR_DELETE_AT
] = delatbl
;
1932 } /* encode_delete_at_attr */
1934 static inline void encode_obj_tags_attr(RGWObjTags
* obj_tags
, map
<string
, bufferlist
>& attrs
)
1936 if (obj_tags
== nullptr){
1937 // we assume the user submitted a tag format which we couldn't parse since
1938 // this wouldn't be parsed later by get/put obj tags, lets delete if the
1939 // attr was populated
1944 obj_tags
->encode(tagsbl
);
1945 attrs
[RGW_ATTR_TAGS
] = tagsbl
;
1948 static inline int encode_dlo_manifest_attr(const char * const dlo_manifest
,
1949 map
<string
, bufferlist
>& attrs
)
1951 string dm
= dlo_manifest
;
1953 if (dm
.find('/') == string::npos
) {
1957 bufferlist manifest_bl
;
1958 manifest_bl
.append(dlo_manifest
, strlen(dlo_manifest
) + 1);
1959 attrs
[RGW_ATTR_USER_MANIFEST
] = manifest_bl
;
1962 } /* encode_dlo_manifest_attr */
1964 static inline void complete_etag(MD5
& hash
, string
*etag
)
1966 char etag_buf
[CEPH_CRYPTO_MD5_DIGESTSIZE
];
1967 char etag_buf_str
[CEPH_CRYPTO_MD5_DIGESTSIZE
* 2 + 16];
1969 hash
.Final((byte
*)etag_buf
);
1970 buf_to_hex((const unsigned char *)etag_buf
, CEPH_CRYPTO_MD5_DIGESTSIZE
,
1973 *etag
= etag_buf_str
;
1974 } /* complete_etag */
1976 class RGWSetAttrs
: public RGWOp
{
1978 map
<string
, buffer::list
> attrs
;
1982 ~RGWSetAttrs() override
{}
1984 void emplace_attr(std::string
&& key
, buffer::list
&& bl
) {
1985 attrs
.emplace(std::move(key
), std::move(bl
));
1988 int verify_permission() override
;
1989 void pre_exec() override
;
1990 void execute() override
;
1992 virtual int get_params() = 0;
1993 void send_response() override
= 0;
1994 const string
name() override
{ return "set_attrs"; }
1995 RGWOpType
get_type() override
{ return RGW_OP_SET_ATTRS
; }
1996 uint32_t op_mask() override
{ return RGW_OP_TYPE_WRITE
; }
1999 class RGWGetObjLayout
: public RGWOp
{
2001 RGWObjManifest
*manifest
{nullptr};
2002 rgw_raw_obj head_obj
;
2008 int check_caps(RGWUserCaps
& caps
) {
2009 return caps
.check_cap("admin", RGW_CAP_READ
);
2011 int verify_permission() {
2012 return check_caps(s
->user
->caps
);
2017 virtual void send_response() = 0;
2018 virtual const string
name() { return "get_obj_layout"; }
2019 virtual RGWOpType
get_type() { return RGW_OP_GET_OBJ_LAYOUT
; }
2020 virtual uint32_t op_mask() { return RGW_OP_TYPE_READ
; }
2023 class RGWPutBucketPolicy
: public RGWOp
{
2025 char *data
= nullptr;
2027 RGWPutBucketPolicy() = default;
2028 ~RGWPutBucketPolicy() {
2030 free(static_cast<void*>(data
));
2033 void send_response() override
;
2034 int verify_permission() override
;
2035 uint32_t op_mask() override
{
2036 return RGW_OP_TYPE_WRITE
;
2038 void execute() override
;
2040 const std::string
name() override
{
2041 return "put_bucket_policy";
2043 RGWOpType
get_type() override
{
2044 return RGW_OP_PUT_BUCKET_POLICY
;
2048 class RGWGetBucketPolicy
: public RGWOp
{
2049 buffer::list policy
;
2051 RGWGetBucketPolicy() = default;
2052 void send_response() override
;
2053 int verify_permission() override
;
2054 uint32_t op_mask() override
{
2055 return RGW_OP_TYPE_READ
;
2057 void execute() override
;
2058 const std::string
name() override
{
2059 return "get_bucket_policy";
2061 RGWOpType
get_type() override
{
2062 return RGW_OP_GET_BUCKET_POLICY
;
2066 class RGWDeleteBucketPolicy
: public RGWOp
{
2068 RGWDeleteBucketPolicy() = default;
2069 void send_response() override
;
2070 int verify_permission() override
;
2071 uint32_t op_mask() override
{
2072 return RGW_OP_TYPE_WRITE
;
2074 void execute() override
;
2076 const std::string
name() override
{
2077 return "delete_bucket_policy";
2079 RGWOpType
get_type() override
{
2080 return RGW_OP_DELETE_BUCKET_POLICY
;
2085 class RGWConfigBucketMetaSearch
: public RGWOp
{
2087 std::map
<std::string
, uint32_t> mdsearch_config
;
2089 RGWConfigBucketMetaSearch() {}
2091 int verify_permission();
2095 virtual int get_params() = 0;
2096 virtual void send_response() = 0;
2097 virtual const string
name() { return "config_bucket_meta_search"; }
2098 virtual RGWOpType
get_type() { return RGW_OP_CONFIG_BUCKET_META_SEARCH
; }
2099 virtual uint32_t op_mask() { return RGW_OP_TYPE_WRITE
; }
2102 class RGWGetBucketMetaSearch
: public RGWOp
{
2104 RGWGetBucketMetaSearch() {}
2106 int verify_permission();
2110 virtual void send_response() = 0;
2111 virtual const string
name() { return "get_bucket_meta_search"; }
2112 virtual RGWOpType
get_type() { return RGW_OP_GET_BUCKET_META_SEARCH
; }
2113 virtual uint32_t op_mask() { return RGW_OP_TYPE_READ
; }
2116 class RGWDelBucketMetaSearch
: public RGWOp
{
2118 RGWDelBucketMetaSearch() {}
2120 int verify_permission();
2124 virtual void send_response() = 0;
2125 virtual const string
name() { return "delete_bucket_meta_search"; }
2126 virtual RGWOpType
delete_type() { return RGW_OP_DEL_BUCKET_META_SEARCH
; }
2127 virtual uint32_t op_mask() { return RGW_OP_TYPE_WRITE
; }
2130 #endif /* CEPH_RGW_OP_H */