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"
45 #include "cls/lock/cls_lock_client.h"
46 #include "cls/rgw/cls_rgw_client.h"
48 #include "include/assert.h"
50 using ceph::crypto::SHA1
;
60 class StrategyRegistry
;
72 int do_init_permissions();
73 int do_read_permissions(RGWOp
* op
, bool only_bucket
);
80 virtual ~RGWHandler();
82 virtual int init(RGWRados
* store
,
84 rgw::io::BasicClient
* cio
);
86 virtual int init_permissions(RGWOp
*) {
90 virtual int retarget(RGWOp
* op
, RGWOp
** new_op
) {
95 virtual int read_permissions(RGWOp
* op
) = 0;
96 virtual int authorize() = 0;
97 virtual int postauth_init() = 0;
98 virtual int error_handler(int err_no
, std::string
* error_content
);
99 virtual void dump(const string
& code
, const string
& message
) const {}
104 void rgw_bucket_object_pre_exec(struct req_state
*s
);
107 * Provide the base class for all ops.
112 RGWHandler
*dialect_handler
;
114 RGWCORSConfiguration bucket_cors
;
116 RGWQuotaInfo bucket_quota
;
117 RGWQuotaInfo user_quota
;
120 int do_aws4_auth_completion();
122 virtual int init_quota();
127 dialect_handler(nullptr),
133 virtual ~RGWOp() = default;
135 int get_ret() const { return op_ret
; }
137 virtual int init_processing() {
138 op_ret
= init_quota();
145 virtual void init(RGWRados
*store
, struct req_state
*s
, RGWHandler
*dialect_handler
) {
148 this->dialect_handler
= dialect_handler
;
150 int read_bucket_cors();
151 bool generate_cors_headers(string
& origin
, string
& method
, string
& headers
, string
& exp_headers
, unsigned *max_age
);
153 virtual int verify_params() { return 0; }
154 virtual bool prefetch_data() { return false; }
156 /* Authenticate requester -- verify its identity.
158 * NOTE: typically the procedure is common across all operations of the same
159 * dialect (S3, Swift API). However, there are significant exceptions in
160 * both APIs: browser uploads, /info and OPTIONS handlers. All of them use
161 * different, specific authentication schema driving the need for per-op
162 * authentication. The alternative is to duplicate parts of the method-
163 * dispatch logic in RGWHandler::authorize() and pollute it with a lot
164 * of special cases. */
165 virtual int verify_requester(const rgw::auth::StrategyRegistry
& auth_registry
) {
166 /* TODO(rzarzynski): rename RGWHandler::authorize to generic_authenticate. */
167 return dialect_handler
->authorize();
169 virtual int verify_permission() = 0;
170 virtual int verify_op_mask();
171 virtual void pre_exec() {}
172 virtual void execute() = 0;
173 virtual void send_response() {}
174 virtual void complete() {
177 virtual const string
name() = 0;
178 virtual RGWOpType
get_type() { return RGW_OP_UNKNOWN
; }
180 virtual uint32_t op_mask() { return 0; }
182 virtual int error_handler(int err_no
, string
*error_content
);
185 class RGWGetObj
: public RGWOp
{
187 seed torrent
; // get torrent
188 const char *range_str
;
190 const char *if_unmod
;
191 const char *if_match
;
192 const char *if_nomatch
;
193 uint32_t mod_zone_id
;
199 ceph::real_time mod_time
;
200 ceph::real_time lastmod
;
201 ceph::real_time unmod_time
;
202 ceph::real_time
*mod_ptr
;
203 ceph::real_time
*unmod_ptr
;
204 map
<string
, bufferlist
> attrs
;
206 bool partial_content
;
209 bool skip_decrypt
{false};
211 utime_t gc_invalidate_time
;
214 bool rgwx_stat
; /* extended rgw stat operation */
218 RGWCompressionInfo cs_info
;
219 off_t first_block
, last_block
;
243 partial_content
= false;
244 range_parsed
= false;
245 skip_manifest
= false;
255 bool prefetch_data() override
;
257 void set_get_data(bool get_data
) {
258 this->get_data
= get_data
;
260 int verify_permission() override
;
261 void pre_exec() override
;
262 void execute() override
;
263 int read_user_manifest_part(
265 const rgw_bucket_dir_entry
& ent
,
266 RGWAccessControlPolicy
* const bucket_acl
,
267 const boost::optional
<rgw::IAM::Policy
>& bucket_policy
,
268 const off_t start_ofs
,
269 const off_t end_ofs
);
270 int handle_user_manifest(const char *prefix
);
271 int handle_slo_manifest(bufferlist
& bl
);
273 int get_data_cb(bufferlist
& bl
, off_t ofs
, off_t len
);
275 virtual int get_params() = 0;
276 virtual int send_response_data_error() = 0;
277 virtual int send_response_data(bufferlist
& bl
, off_t ofs
, off_t len
) = 0;
279 const string
name() override
{ return "get_obj"; }
280 RGWOpType
get_type() override
{ return RGW_OP_GET_OBJ
; }
281 uint32_t op_mask() override
{ return RGW_OP_TYPE_READ
; }
282 virtual bool need_object_expiration() { return false; }
284 * calculates filter used to decrypt RGW objects data
286 virtual int get_decrypt_filter(std::unique_ptr
<RGWGetDataCB
>* filter
, RGWGetDataCB
* cb
, bufferlist
* manifest_bl
) {
292 class RGWGetObj_CB
: public RGWGetDataCB
296 explicit RGWGetObj_CB(RGWGetObj
*_op
) : op(_op
) {}
297 ~RGWGetObj_CB() override
{}
299 int handle_data(bufferlist
& bl
, off_t bl_ofs
, off_t bl_len
) override
{
300 return op
->get_data_cb(bl
, bl_ofs
, bl_len
);
304 class RGWGetObj_Filter
: public RGWGetDataCB
309 RGWGetObj_Filter(RGWGetDataCB
* next
): next(next
) {}
310 ~RGWGetObj_Filter() override
{}
312 * Passes data through filter.
313 * Filter can modify content of bl.
314 * When bl_len == 0 , it means 'flush
316 int handle_data(bufferlist
& bl
, off_t bl_ofs
, off_t bl_len
) override
{
317 return next
->handle_data(bl
, bl_ofs
, bl_len
);
320 * Flushes any cached data. Used by RGWGetObjFilter.
321 * Return logic same as handle_data.
323 int flush() override
{
324 return next
->flush();
327 * Allows filter to extend range required for successful filtering
329 int fixup_range(off_t
& ofs
, off_t
& end
) override
{
330 return next
->fixup_range(ofs
, end
);
334 class RGWGetObjTags
: public RGWOp
{
337 bool has_tags
{false};
339 int verify_permission();
343 virtual void send_response_data(bufferlist
& bl
) = 0;
344 virtual const string
name() noexcept override
{ return "get_obj_tags"; }
345 virtual uint32_t op_mask() { return RGW_OP_TYPE_READ
; }
346 RGWOpType
get_type() { return RGW_OP_GET_OBJ_TAGGING
; }
350 class RGWPutObjTags
: public RGWOp
{
354 int verify_permission();
357 virtual void send_response() = 0;
358 virtual int get_params() = 0;
359 virtual const string
name() { return "put_obj_tags"; }
360 virtual uint32_t op_mask() { return RGW_OP_TYPE_WRITE
; }
361 RGWOpType
get_type() { return RGW_OP_PUT_OBJ_TAGGING
; }
365 class RGWDeleteObjTags
: public RGWOp
{
368 int verify_permission();
371 virtual void send_response() = 0;
372 virtual const string
name() { return "delete_obj_tags"; }
373 virtual uint32_t op_mask() { return RGW_OP_TYPE_DELETE
; }
374 RGWOpType
get_type() { return RGW_OP_DELETE_OBJ_TAGGING
;}
377 class RGWBulkDelete
: public RGWOp
{
380 std::string bucket_name
;
391 unsigned int num_deleted
;
392 unsigned int num_unfound
;
393 std::list
<fail_desc_t
> failures
;
395 RGWRados
* const store
;
399 Deleter(RGWRados
* const str
, req_state
* const s
)
406 unsigned int get_num_deleted() const {
410 unsigned int get_num_unfound() const {
414 const std::list
<fail_desc_t
> get_failures() const {
418 bool verify_permission(RGWBucketInfo
& binfo
,
419 map
<string
, bufferlist
>& battrs
,
420 ACLOwner
& bucket_owner
/* out */);
421 bool delete_single(const acct_path_t
& path
);
422 bool delete_chunk(const std::list
<acct_path_t
>& paths
);
424 /* End of Deleter subclass */
426 static const size_t MAX_CHUNK_ENTRIES
= 1024;
429 std::unique_ptr
<Deleter
> deleter
;
436 int verify_permission() override
;
437 void pre_exec() override
;
438 void execute() override
;
440 virtual int get_data(std::list
<acct_path_t
>& items
,
441 bool * is_truncated
) = 0;
442 void send_response() override
= 0;
444 const string
name() override
{ return "bulk_delete"; }
445 RGWOpType
get_type() override
{ return RGW_OP_BULK_DELETE
; }
446 uint32_t op_mask() override
{ return RGW_OP_TYPE_DELETE
; }
449 inline ostream
& operator<<(ostream
& out
, const RGWBulkDelete::acct_path_t
&o
) {
450 return out
<< o
.bucket_name
<< "/" << o
.obj_key
;
454 class RGWBulkUploadOp
: public RGWOp
{
455 boost::optional
<RGWObjectCtx
> dir_ctx
;
460 fail_desc_t(const int err
, std::string path
)
462 path(std::move(path
)) {
466 const std::string path
;
469 static constexpr std::array
<int, 2> terminal_errors
= {
473 /* FIXME: boost::container::small_vector<fail_desc_t, 4> failures; */
474 std::vector
<fail_desc_t
> failures
;
478 class DecoratedStreamGetter
;
479 class AlignedStreamGetter
;
481 virtual std::unique_ptr
<StreamGetter
> create_stream() = 0;
482 virtual void send_response() = 0;
484 boost::optional
<std::pair
<std::string
, rgw_obj_key
>>
485 parse_path(const boost::string_ref
& path
);
487 std::pair
<std::string
, std::string
>
488 handle_upload_path(struct req_state
*s
);
490 bool handle_file_verify_permission(RGWBucketInfo
& binfo
,
492 std::map
<std::string
, ceph::bufferlist
>& battrs
,
493 ACLOwner
& bucket_owner
/* out */);
494 int handle_file(boost::string_ref path
,
496 AlignedStreamGetter
& body
);
498 int handle_dir_verify_permission();
499 int handle_dir(boost::string_ref path
);
506 void init(RGWRados
* const store
,
507 struct req_state
* const s
,
508 RGWHandler
* const h
) override
{
509 RGWOp::init(store
, s
, h
);
510 dir_ctx
.emplace(store
);
513 int verify_permission() override
;
514 void pre_exec() override
;
515 void execute() override
;
517 const std::string
name() override
{
518 return "bulk_upload";
521 RGWOpType
get_type() override
{
522 return RGW_OP_BULK_UPLOAD
;
525 uint32_t op_mask() override
{
526 return RGW_OP_TYPE_WRITE
;
528 }; /* RGWBulkUploadOp */
531 class RGWBulkUploadOp::StreamGetter
{
533 StreamGetter() = default;
534 virtual ~StreamGetter() = default;
536 virtual ssize_t
get_at_most(size_t want
, ceph::bufferlist
& dst
) = 0;
537 virtual ssize_t
get_exactly(size_t want
, ceph::bufferlist
& dst
) = 0;
538 }; /* End of nested subclass StreamGetter */
541 class RGWBulkUploadOp::DecoratedStreamGetter
: public StreamGetter
{
542 StreamGetter
& decoratee
;
545 StreamGetter
& get_decoratee() {
550 DecoratedStreamGetter(StreamGetter
& decoratee
)
551 : decoratee(decoratee
) {
553 virtual ~DecoratedStreamGetter() = default;
555 ssize_t
get_at_most(const size_t want
, ceph::bufferlist
& dst
) override
{
556 return get_decoratee().get_at_most(want
, dst
);
559 ssize_t
get_exactly(const size_t want
, ceph::bufferlist
& dst
) override
{
560 return get_decoratee().get_exactly(want
, dst
);
562 }; /* RGWBulkUploadOp::DecoratedStreamGetter */
565 class RGWBulkUploadOp::AlignedStreamGetter
566 : public RGWBulkUploadOp::DecoratedStreamGetter
{
572 template <typename U
>
573 AlignedStreamGetter(const size_t position
,
575 const size_t alignment
,
577 : DecoratedStreamGetter(std::forward
<U
>(decoratee
)),
580 alignment(alignment
) {
582 virtual ~AlignedStreamGetter();
583 ssize_t
get_at_most(size_t want
, ceph::bufferlist
& dst
) override
;
584 ssize_t
get_exactly(size_t want
, ceph::bufferlist
& dst
) override
;
585 }; /* RGWBulkUploadOp::AlignedStreamGetter */
588 struct RGWUsageStats
{
589 uint64_t bytes_used
= 0;
590 uint64_t bytes_used_rounded
= 0;
591 uint64_t buckets_count
= 0;
592 uint64_t objects_count
= 0;
595 #define RGW_LIST_BUCKETS_LIMIT_MAX 10000
597 class RGWListBuckets
: public RGWOp
{
601 std::string end_marker
;
604 std::map
<std::string
, ceph::bufferlist
> attrs
;
607 RGWUsageStats global_stats
;
608 std::map
<std::string
, RGWUsageStats
> policies_stats
;
610 virtual uint64_t get_default_max() const {
617 limit(RGW_LIST_BUCKETS_LIMIT_MAX
),
618 limit_max(RGW_LIST_BUCKETS_LIMIT_MAX
),
619 is_truncated(false) {
622 int verify_permission() override
;
623 void execute() override
;
625 virtual int get_params() = 0;
626 virtual void handle_listing_chunk(RGWUserBuckets
&& buckets
) {
627 /* The default implementation, used by e.g. S3, just generates a new
628 * part of listing and sends it client immediately. Swift can behave
629 * differently: when the reverse option is requested, all incoming
630 * instances of RGWUserBuckets are buffered and finally reversed. */
631 return send_response_data(buckets
);
633 virtual void send_response_begin(bool has_buckets
) = 0;
634 virtual void send_response_data(RGWUserBuckets
& buckets
) = 0;
635 virtual void send_response_end() = 0;
636 void send_response() override
{}
638 virtual bool should_get_stats() { return false; }
639 virtual bool supports_account_metadata() { return false; }
641 const string
name() override
{ return "list_buckets"; }
642 RGWOpType
get_type() override
{ return RGW_OP_LIST_BUCKETS
; }
643 uint32_t op_mask() override
{ return RGW_OP_TYPE_READ
; }
646 class RGWGetUsage
: public RGWOp
{
651 int show_log_entries
;
653 map
<string
, bool> categories
;
654 map
<rgw_user_bucket
, rgw_usage_log_entry
> usage
;
655 map
<string
, rgw_usage_log_entry
> summary_map
;
656 map
<string
, cls_user_bucket_entry
> buckets_usage
;
657 cls_user_header header
;
659 RGWGetUsage() : sent_data(false), show_log_entries(true), show_log_sum(true){
662 int verify_permission() override
;
663 void execute() override
;
665 virtual int get_params() = 0;
666 void send_response() override
{}
668 virtual bool should_get_stats() { return false; }
670 const string
name() override
{ return "get_usage"; }
671 uint32_t op_mask() override
{ return RGW_OP_TYPE_READ
; }
674 class RGWStatAccount
: public RGWOp
{
676 RGWUsageStats global_stats
;
677 std::map
<std::string
, RGWUsageStats
> policies_stats
;
680 RGWStatAccount() = default;
682 int verify_permission() override
;
683 void execute() override
;
685 void send_response() override
= 0;
686 const std::string
name() override
{ return "stat_account"; }
687 RGWOpType
get_type() override
{ return RGW_OP_STAT_ACCOUNT
; }
688 uint32_t op_mask() override
{ return RGW_OP_TYPE_READ
; }
691 class RGWListBucket
: public RGWOp
{
696 rgw_obj_key next_marker
;
697 rgw_obj_key end_marker
;
700 string encoding_type
;
703 vector
<rgw_bucket_dir_entry
> objs
;
704 map
<string
, bool> common_prefixes
;
711 int parse_max_keys();
714 RGWListBucket() : list_versions(false), max(0),
715 default_max(0), is_truncated(false), shard_id(-1) {}
716 int verify_permission() override
;
717 void pre_exec() override
;
718 void execute() override
;
720 virtual int get_params() = 0;
721 void send_response() override
= 0;
722 const string
name() override
{ return "list_bucket"; }
723 RGWOpType
get_type() override
{ return RGW_OP_LIST_BUCKET
; }
724 uint32_t op_mask() override
{ return RGW_OP_TYPE_READ
; }
725 virtual bool need_container_stats() { return false; }
728 class RGWGetBucketLogging
: public RGWOp
{
730 RGWGetBucketLogging() {}
731 int verify_permission() override
;
732 void execute() override
{ }
734 void send_response() override
= 0;
735 const string
name() override
{ return "get_bucket_logging"; }
736 RGWOpType
get_type() override
{ return RGW_OP_GET_BUCKET_LOGGING
; }
737 uint32_t op_mask() override
{ return RGW_OP_TYPE_READ
; }
740 class RGWGetBucketLocation
: public RGWOp
{
742 RGWGetBucketLocation() {}
743 ~RGWGetBucketLocation() override
{}
744 int verify_permission() override
;
745 void execute() override
{ }
747 void send_response() override
= 0;
748 const string
name() override
{ return "get_bucket_location"; }
749 RGWOpType
get_type() override
{ return RGW_OP_GET_BUCKET_LOCATION
; }
750 uint32_t op_mask() override
{ return RGW_OP_TYPE_READ
; }
753 class RGWGetBucketVersioning
: public RGWOp
{
756 bool versioning_enabled
;
758 RGWGetBucketVersioning() : versioned(false), versioning_enabled(false) {}
760 int verify_permission() override
;
761 void pre_exec() override
;
762 void execute() override
;
764 void send_response() override
= 0;
765 const string
name() override
{ return "get_bucket_versioning"; }
766 RGWOpType
get_type() override
{ return RGW_OP_GET_BUCKET_VERSIONING
; }
767 uint32_t op_mask() override
{ return RGW_OP_TYPE_READ
; }
770 class RGWSetBucketVersioning
: public RGWOp
{
772 bool enable_versioning
;
775 RGWSetBucketVersioning() : enable_versioning(false) {}
777 int verify_permission() override
;
778 void pre_exec() override
;
779 void execute() override
;
781 virtual int get_params() { return 0; }
783 void send_response() override
= 0;
784 const string
name() override
{ return "set_bucket_versioning"; }
785 RGWOpType
get_type() override
{ return RGW_OP_SET_BUCKET_VERSIONING
; }
786 uint32_t op_mask() override
{ return RGW_OP_TYPE_WRITE
; }
789 class RGWGetBucketWebsite
: public RGWOp
{
791 RGWGetBucketWebsite() {}
793 int verify_permission() override
;
794 void pre_exec() override
;
795 void execute() override
;
797 void send_response() override
= 0;
798 const string
name() override
{ return "get_bucket_website"; }
799 RGWOpType
get_type() override
{ return RGW_OP_GET_BUCKET_WEBSITE
; }
800 uint32_t op_mask() override
{ return RGW_OP_TYPE_READ
; }
803 class RGWSetBucketWebsite
: public RGWOp
{
806 RGWBucketWebsiteConf website_conf
;
808 RGWSetBucketWebsite() {}
810 int verify_permission() override
;
811 void pre_exec() override
;
812 void execute() override
;
814 virtual int get_params() { return 0; }
816 void send_response() override
= 0;
817 const string
name() override
{ return "set_bucket_website"; }
818 RGWOpType
get_type() override
{ return RGW_OP_SET_BUCKET_WEBSITE
; }
819 uint32_t op_mask() override
{ return RGW_OP_TYPE_WRITE
; }
822 class RGWDeleteBucketWebsite
: public RGWOp
{
824 RGWDeleteBucketWebsite() {}
826 int verify_permission() override
;
827 void pre_exec() override
;
828 void execute() override
;
830 void send_response() override
= 0;
831 const string
name() override
{ return "delete_bucket_website"; }
832 RGWOpType
get_type() override
{ return RGW_OP_SET_BUCKET_WEBSITE
; }
833 uint32_t op_mask() override
{ return RGW_OP_TYPE_WRITE
; }
836 class RGWStatBucket
: public RGWOp
{
842 ~RGWStatBucket() override
{}
844 int verify_permission() override
;
845 void pre_exec() override
;
846 void execute() override
;
848 void send_response() override
= 0;
849 const string
name() override
{ return "stat_bucket"; }
850 RGWOpType
get_type() override
{ return RGW_OP_STAT_BUCKET
; }
851 uint32_t op_mask() override
{ return RGW_OP_TYPE_READ
; }
854 class RGWCreateBucket
: public RGWOp
{
856 RGWAccessControlPolicy policy
;
857 string location_constraint
;
858 string placement_rule
;
862 RGWCORSConfiguration cors_config
;
863 boost::optional
<std::string
> swift_ver_location
;
864 map
<string
, buffer::list
> attrs
;
865 set
<string
> rmattr_names
;
869 virtual bool need_metadata_upload() const { return false; }
872 RGWCreateBucket() : has_cors(false) {}
874 void emplace_attr(std::string
&& key
, buffer::list
&& bl
) {
875 attrs
.emplace(std::move(key
), std::move(bl
)); /* key and bl are r-value refs */
878 int verify_permission() override
;
879 void pre_exec() override
;
880 void execute() override
;
881 void init(RGWRados
*store
, struct req_state
*s
, RGWHandler
*h
) override
{
882 RGWOp::init(store
, s
, h
);
883 policy
.set_ctx(s
->cct
);
885 virtual int get_params() { return 0; }
886 void send_response() override
= 0;
887 const string
name() override
{ return "create_bucket"; }
888 RGWOpType
get_type() override
{ return RGW_OP_CREATE_BUCKET
; }
889 uint32_t op_mask() override
{ return RGW_OP_TYPE_WRITE
; }
892 class RGWDeleteBucket
: public RGWOp
{
894 RGWObjVersionTracker objv_tracker
;
899 int verify_permission() override
;
900 void pre_exec() override
;
901 void execute() override
;
903 void send_response() override
= 0;
904 const string
name() override
{ return "delete_bucket"; }
905 RGWOpType
get_type() override
{ return RGW_OP_DELETE_BUCKET
; }
906 uint32_t op_mask() override
{ return RGW_OP_TYPE_DELETE
; }
909 struct rgw_slo_entry
{
914 rgw_slo_entry() : size_bytes(0) {}
916 void encode(bufferlist
& bl
) const {
917 ENCODE_START(1, 1, bl
);
920 ::encode(size_bytes
, bl
);
924 void decode(bufferlist::iterator
& bl
) {
928 ::decode(size_bytes
, bl
);
932 void decode_json(JSONObj
*obj
);
934 WRITE_CLASS_ENCODER(rgw_slo_entry
)
937 vector
<rgw_slo_entry
> entries
;
944 RGWSLOInfo() : total_size(0), raw_data(NULL
), raw_data_len(0) {}
949 void encode(bufferlist
& bl
) const {
950 ENCODE_START(1, 1, bl
);
951 ::encode(entries
, bl
);
952 ::encode(total_size
, bl
);
956 void decode(bufferlist::iterator
& bl
) {
958 ::decode(entries
, bl
);
959 ::decode(total_size
, bl
);
963 WRITE_CLASS_ENCODER(RGWSLOInfo
)
965 class RGWPutObj
: public RGWOp
{
967 friend class RGWPutObjProcessor
;
972 const char *supplied_md5_b64
;
973 const char *supplied_etag
;
974 const char *if_match
;
975 const char *if_nomatch
;
976 const char *copy_source
;
977 const char *copy_source_range
;
978 RGWBucketInfo copy_source_bucket_info
;
979 string copy_source_tenant_name
;
980 string copy_source_bucket_name
;
981 string copy_source_object_name
;
982 string copy_source_version_id
;
983 off_t copy_source_range_fst
;
984 off_t copy_source_range_lst
;
987 RGWAccessControlPolicy policy
;
988 std::unique_ptr
<RGWObjTags
> obj_tags
;
989 const char *dlo_manifest
;
990 RGWSLOInfo
*slo_info
;
991 map
<string
, bufferlist
> attrs
;
992 ceph::real_time mtime
;
996 map
<string
, string
> crypt_http_responses
;
999 boost::optional
<ceph::real_time
> delete_at
;
1002 RGWPutObj() : ofs(0),
1003 supplied_md5_b64(NULL
),
1004 supplied_etag(NULL
),
1008 copy_source_range(NULL
),
1009 copy_source_range_fst(0),
1010 copy_source_range_lst(0),
1016 ~RGWPutObj() override
{
1020 void init(RGWRados
*store
, struct req_state
*s
, RGWHandler
*h
) override
{
1021 RGWOp::init(store
, s
, h
);
1022 policy
.set_ctx(s
->cct
);
1025 void emplace_attr(std::string
&& key
, buffer::list
&& bl
) {
1026 attrs
.emplace(std::move(key
), std::move(bl
)); /* key and bl are r-value refs */
1029 virtual RGWPutObjProcessor
*select_processor(RGWObjectCtx
& obj_ctx
, bool *is_multipart
);
1030 void dispose_processor(RGWPutObjDataProcessor
*processor
);
1032 int verify_permission() override
;
1033 void pre_exec() override
;
1034 void execute() override
;
1036 /* this is for cases when copying data from other object */
1037 virtual int get_decrypt_filter(std::unique_ptr
<RGWGetDataCB
>* filter
,
1039 map
<string
, bufferlist
>& attrs
,
1040 bufferlist
* manifest_bl
) {
1044 virtual int get_encrypt_filter(std::unique_ptr
<RGWPutObjDataProcessor
> *filter
, RGWPutObjDataProcessor
* cb
) {
1049 int get_data_cb(bufferlist
& bl
, off_t bl_ofs
, off_t bl_len
);
1050 int get_data(const off_t fst
, const off_t lst
, bufferlist
& bl
);
1052 virtual int get_params() = 0;
1053 virtual int get_data(bufferlist
& bl
) = 0;
1054 void send_response() override
= 0;
1055 const string
name() override
{ return "put_obj"; }
1056 RGWOpType
get_type() override
{ return RGW_OP_PUT_OBJ
; }
1057 uint32_t op_mask() override
{ return RGW_OP_TYPE_WRITE
; }
1060 class RGWPutObj_Filter
: public RGWPutObjDataProcessor
1063 RGWPutObjDataProcessor
* next
;
1065 RGWPutObj_Filter(RGWPutObjDataProcessor
* next
) :
1067 ~RGWPutObj_Filter() override
{}
1068 int handle_data(bufferlist
& bl
, off_t ofs
, void **phandle
, rgw_raw_obj
*pobj
, bool *again
) override
{
1069 return next
->handle_data(bl
, ofs
, phandle
, pobj
, again
);
1071 int throttle_data(void *handle
, const rgw_raw_obj
& obj
, uint64_t size
, bool need_to_wait
) override
{
1072 return next
->throttle_data(handle
, obj
, size
, need_to_wait
);
1074 }; /* RGWPutObj_Filter */
1076 class RGWPostObj
: public RGWOp
{
1082 const char *supplied_md5_b64
;
1083 const char *supplied_etag
;
1085 RGWAccessControlPolicy policy
;
1086 map
<string
, bufferlist
> attrs
;
1087 boost::optional
<ceph::real_time
> delete_at
;
1089 /* Must be called after get_data() or the result is undefined. */
1090 virtual std::string
get_current_filename() const = 0;
1091 virtual std::string
get_current_content_type() const = 0;
1092 virtual bool is_next_file_to_upload() {
1096 RGWPostObj() : min_len(0),
1100 supplied_md5_b64(nullptr),
1101 supplied_etag(nullptr) {
1104 void emplace_attr(std::string
&& key
, buffer::list
&& bl
) {
1105 attrs
.emplace(std::move(key
), std::move(bl
)); /* key and bl are r-value refs */
1108 void init(RGWRados
*store
, struct req_state
*s
, RGWHandler
*h
) override
{
1109 RGWOp::init(store
, s
, h
);
1110 policy
.set_ctx(s
->cct
);
1113 int verify_permission() override
;
1114 void pre_exec() override
;
1115 void execute() override
;
1117 virtual int get_encrypt_filter(std::unique_ptr
<RGWPutObjDataProcessor
> *filter
, RGWPutObjDataProcessor
* cb
) {
1121 virtual int get_params() = 0;
1122 virtual int get_data(ceph::bufferlist
& bl
, bool& again
) = 0;
1123 void send_response() override
= 0;
1124 const std::string
name() override
{ return "post_obj"; }
1125 RGWOpType
get_type() override
{ return RGW_OP_POST_OBJ
; }
1126 uint32_t op_mask() override
{ return RGW_OP_TYPE_WRITE
; }
1129 class RGWPutMetadataAccount
: public RGWOp
{
1131 std::set
<std::string
> rmattr_names
;
1132 std::map
<std::string
, bufferlist
> attrs
, orig_attrs
;
1133 std::map
<int, std::string
> temp_url_keys
;
1134 RGWQuotaInfo new_quota
;
1135 bool new_quota_extracted
;
1137 RGWObjVersionTracker acct_op_tracker
;
1139 RGWAccessControlPolicy policy
;
1143 RGWPutMetadataAccount()
1144 : new_quota_extracted(false),
1148 void init(RGWRados
*store
, struct req_state
*s
, RGWHandler
*h
) override
{
1149 RGWOp::init(store
, s
, h
);
1150 policy
.set_ctx(s
->cct
);
1152 int init_processing() override
;
1153 int verify_permission() override
;
1154 void pre_exec() override
{ }
1155 void execute() override
;
1157 virtual int get_params() = 0;
1158 void send_response() override
= 0;
1159 virtual void filter_out_temp_url(map
<string
, bufferlist
>& add_attrs
,
1160 const set
<string
>& rmattr_names
,
1161 map
<int, string
>& temp_url_keys
);
1162 const string
name() override
{ return "put_account_metadata"; }
1163 RGWOpType
get_type() override
{ return RGW_OP_PUT_METADATA_ACCOUNT
; }
1164 uint32_t op_mask() override
{ return RGW_OP_TYPE_WRITE
; }
1167 class RGWPutMetadataBucket
: public RGWOp
{
1169 map
<string
, buffer::list
> attrs
;
1170 set
<string
> rmattr_names
;
1171 bool has_policy
, has_cors
;
1172 uint32_t policy_rw_mask
;
1173 RGWAccessControlPolicy policy
;
1174 RGWCORSConfiguration cors_config
;
1175 string placement_rule
;
1176 boost::optional
<std::string
> swift_ver_location
;
1179 RGWPutMetadataBucket()
1180 : has_policy(false), has_cors(false), policy_rw_mask(0)
1183 void emplace_attr(std::string
&& key
, buffer::list
&& bl
) {
1184 attrs
.emplace(std::move(key
), std::move(bl
)); /* key and bl are r-value refs */
1187 void init(RGWRados
*store
, struct req_state
*s
, RGWHandler
*h
) override
{
1188 RGWOp::init(store
, s
, h
);
1189 policy
.set_ctx(s
->cct
);
1192 int verify_permission() override
;
1193 void pre_exec() override
;
1194 void execute() override
;
1196 virtual int get_params() = 0;
1197 void send_response() override
= 0;
1198 const string
name() override
{ return "put_bucket_metadata"; }
1199 RGWOpType
get_type() override
{ return RGW_OP_PUT_METADATA_BUCKET
; }
1200 uint32_t op_mask() override
{ return RGW_OP_TYPE_WRITE
; }
1203 class RGWPutMetadataObject
: public RGWOp
{
1205 RGWAccessControlPolicy policy
;
1206 string placement_rule
;
1207 boost::optional
<ceph::real_time
> delete_at
;
1208 const char *dlo_manifest
;
1211 RGWPutMetadataObject()
1212 : dlo_manifest(NULL
)
1215 void init(RGWRados
*store
, struct req_state
*s
, RGWHandler
*h
) override
{
1216 RGWOp::init(store
, s
, h
);
1217 policy
.set_ctx(s
->cct
);
1219 int verify_permission() override
;
1220 void pre_exec() override
;
1221 void execute() override
;
1223 virtual int get_params() = 0;
1224 void send_response() override
= 0;
1225 const string
name() override
{ return "put_obj_metadata"; }
1226 RGWOpType
get_type() override
{ return RGW_OP_PUT_METADATA_OBJECT
; }
1227 uint32_t op_mask() override
{ return RGW_OP_TYPE_WRITE
; }
1228 virtual bool need_object_expiration() { return false; }
1231 class RGWDeleteObj
: public RGWOp
{
1234 bool multipart_delete
;
1236 ceph::real_time unmod_since
; /* if unmodified since */
1237 bool no_precondition_error
;
1238 std::unique_ptr
<RGWBulkDelete::Deleter
> deleter
;
1242 : delete_marker(false),
1243 multipart_delete(false),
1244 no_precondition_error(false),
1248 int verify_permission() override
;
1249 void pre_exec() override
;
1250 void execute() override
;
1251 int handle_slo_manifest(bufferlist
& bl
);
1253 virtual int get_params() { return 0; }
1254 void send_response() override
= 0;
1255 const string
name() override
{ return "delete_obj"; }
1256 RGWOpType
get_type() override
{ return RGW_OP_DELETE_OBJ
; }
1257 uint32_t op_mask() override
{ return RGW_OP_TYPE_DELETE
; }
1258 virtual bool need_object_expiration() { return false; }
1261 class RGWCopyObj
: public RGWOp
{
1263 RGWAccessControlPolicy dest_policy
;
1265 const char *if_unmod
;
1266 const char *if_match
;
1267 const char *if_nomatch
;
1271 ceph::real_time mod_time
;
1272 ceph::real_time unmod_time
;
1273 ceph::real_time
*mod_ptr
;
1274 ceph::real_time
*unmod_ptr
;
1275 map
<string
, buffer::list
> attrs
;
1276 string src_tenant_name
, src_bucket_name
;
1277 rgw_bucket src_bucket
;
1278 rgw_obj_key src_object
;
1279 string dest_tenant_name
, dest_bucket_name
;
1280 rgw_bucket dest_bucket
;
1282 ceph::real_time src_mtime
;
1283 ceph::real_time mtime
;
1284 RGWRados::AttrsMod attrs_mod
;
1285 RGWBucketInfo src_bucket_info
;
1286 RGWBucketInfo dest_bucket_info
;
1290 ceph::buffer::list etag
;
1297 boost::optional
<ceph::real_time
> delete_at
;
1313 attrs_mod
= RGWRados::ATTRSMOD_NONE
;
1316 copy_if_newer
= false;
1319 static bool parse_copy_location(const string
& src
,
1320 string
& bucket_name
,
1321 rgw_obj_key
& object
);
1323 void emplace_attr(std::string
&& key
, buffer::list
&& bl
) {
1324 attrs
.emplace(std::move(key
), std::move(bl
));
1327 void init(RGWRados
*store
, struct req_state
*s
, RGWHandler
*h
) override
{
1328 RGWOp::init(store
, s
, h
);
1329 dest_policy
.set_ctx(s
->cct
);
1331 int verify_permission() override
;
1332 void pre_exec() override
;
1333 void execute() override
;
1334 void progress_cb(off_t ofs
);
1336 virtual int init_dest_policy() { return 0; }
1337 virtual int get_params() = 0;
1338 virtual void send_partial_response(off_t ofs
) {}
1339 void send_response() override
= 0;
1340 const string
name() override
{ return "copy_obj"; }
1341 RGWOpType
get_type() override
{ return RGW_OP_COPY_OBJ
; }
1342 uint32_t op_mask() override
{ return RGW_OP_TYPE_WRITE
; }
1345 class RGWGetACLs
: public RGWOp
{
1352 int verify_permission() override
;
1353 void pre_exec() override
;
1354 void execute() override
;
1356 void send_response() override
= 0;
1357 const string
name() override
{ return "get_acls"; }
1358 RGWOpType
get_type() override
{ return RGW_OP_GET_ACLS
; }
1359 uint32_t op_mask() override
{ return RGW_OP_TYPE_READ
; }
1362 class RGWPutACLs
: public RGWOp
{
1373 ~RGWPutACLs() override
{
1377 int verify_permission() override
;
1378 void pre_exec() override
;
1379 void execute() override
;
1381 virtual int get_policy_from_state(RGWRados
*store
, struct req_state
*s
, stringstream
& ss
) { return 0; }
1382 virtual int get_params() = 0;
1383 void send_response() override
= 0;
1384 const string
name() override
{ return "put_acls"; }
1385 RGWOpType
get_type() override
{ return RGW_OP_PUT_ACLS
; }
1386 uint32_t op_mask() override
{ return RGW_OP_TYPE_WRITE
; }
1389 class RGWGetLC
: public RGWOp
{
1394 ~RGWGetLC() override
{ }
1396 int verify_permission() override
;
1397 void pre_exec() override
;
1398 void execute() override
= 0;
1400 void send_response() override
= 0;
1401 const string
name() override
{ return "get_lifecycle"; }
1402 RGWOpType
get_type() override
{ return RGW_OP_GET_LC
; }
1403 uint32_t op_mask() override
{ return RGW_OP_TYPE_READ
; }
1406 class RGWPutLC
: public RGWOp
{
1410 const char *content_md5
;
1417 content_md5
= nullptr;
1419 ~RGWPutLC() override
{
1423 void init(RGWRados
*store
, struct req_state
*s
, RGWHandler
*dialect_handler
) override
{
1424 #define COOKIE_LEN 16
1425 char buf
[COOKIE_LEN
+ 1];
1427 RGWOp::init(store
, s
, dialect_handler
);
1428 gen_rand_alphanumeric(s
->cct
, buf
, sizeof(buf
) - 1);
1432 int verify_permission() override
;
1433 void pre_exec() override
;
1434 void execute() override
;
1436 // virtual int get_policy_from_state(RGWRados *store, struct req_state *s, stringstream& ss) { return 0; }
1437 virtual int get_params() = 0;
1438 void send_response() override
= 0;
1439 const string
name() override
{ return "put_lifecycle"; }
1440 RGWOpType
get_type() override
{ return RGW_OP_PUT_LC
; }
1441 uint32_t op_mask() override
{ return RGW_OP_TYPE_WRITE
; }
1444 class RGWDeleteLC
: public RGWOp
{
1454 ~RGWDeleteLC() override
{
1458 int verify_permission() override
;
1459 void pre_exec() override
;
1460 void execute() override
;
1462 void send_response() override
= 0;
1463 const string
name() override
{ return "delete_lifecycle"; }
1464 RGWOpType
get_type() override
{ return RGW_OP_DELETE_LC
; }
1465 uint32_t op_mask() override
{ return RGW_OP_TYPE_WRITE
; }
1468 class RGWGetCORS
: public RGWOp
{
1474 int verify_permission() override
;
1475 void execute() override
;
1477 void send_response() override
= 0;
1478 const string
name() override
{ return "get_cors"; }
1479 RGWOpType
get_type() override
{ return RGW_OP_GET_CORS
; }
1480 uint32_t op_mask() override
{ return RGW_OP_TYPE_READ
; }
1483 class RGWPutCORS
: public RGWOp
{
1490 ~RGWPutCORS() override
{}
1492 int verify_permission() override
;
1493 void execute() override
;
1495 virtual int get_params() = 0;
1496 void send_response() override
= 0;
1497 const string
name() override
{ return "put_cors"; }
1498 RGWOpType
get_type() override
{ return RGW_OP_PUT_CORS
; }
1499 uint32_t op_mask() override
{ return RGW_OP_TYPE_WRITE
; }
1502 class RGWDeleteCORS
: public RGWOp
{
1508 int verify_permission() override
;
1509 void execute() override
;
1511 void send_response() override
= 0;
1512 const string
name() override
{ return "delete_cors"; }
1513 RGWOpType
get_type() override
{ return RGW_OP_DELETE_CORS
; }
1514 uint32_t op_mask() override
{ return RGW_OP_TYPE_WRITE
; }
1517 class RGWOptionsCORS
: public RGWOp
{
1520 const char *origin
, *req_hdrs
, *req_meth
;
1523 RGWOptionsCORS() : rule(NULL
), origin(NULL
),
1524 req_hdrs(NULL
), req_meth(NULL
) {
1527 int verify_permission() override
{return 0;}
1528 int validate_cors_request(RGWCORSConfiguration
*cc
);
1529 void execute() override
;
1530 void get_response_params(string
& allowed_hdrs
, string
& exp_hdrs
, unsigned *max_age
);
1531 void send_response() override
= 0;
1532 const string
name() override
{ return "options_cors"; }
1533 RGWOpType
get_type() override
{ return RGW_OP_OPTIONS_CORS
; }
1534 uint32_t op_mask() override
{ return RGW_OP_TYPE_READ
; }
1537 class RGWGetRequestPayment
: public RGWOp
{
1539 bool requester_pays
;
1542 RGWGetRequestPayment() : requester_pays(0) {}
1544 int verify_permission() override
;
1545 void pre_exec() override
;
1546 void execute() override
;
1548 void send_response() override
= 0;
1549 const string
name() override
{ return "get_request_payment"; }
1550 RGWOpType
get_type() override
{ return RGW_OP_GET_REQUEST_PAYMENT
; }
1551 uint32_t op_mask() override
{ return RGW_OP_TYPE_READ
; }
1554 class RGWSetRequestPayment
: public RGWOp
{
1556 bool requester_pays
;
1558 RGWSetRequestPayment() : requester_pays(false) {}
1560 int verify_permission() override
;
1561 void pre_exec() override
;
1562 void execute() override
;
1564 virtual int get_params() { return 0; }
1566 void send_response() override
= 0;
1567 const string
name() override
{ return "set_request_payment"; }
1568 RGWOpType
get_type() override
{ return RGW_OP_SET_REQUEST_PAYMENT
; }
1569 uint32_t op_mask() override
{ return RGW_OP_TYPE_WRITE
; }
1572 class RGWInitMultipart
: public RGWOp
{
1575 RGWAccessControlPolicy policy
;
1578 RGWInitMultipart() {}
1580 void init(RGWRados
*store
, struct req_state
*s
, RGWHandler
*h
) override
{
1581 RGWOp::init(store
, s
, h
);
1582 policy
.set_ctx(s
->cct
);
1584 int verify_permission() override
;
1585 void pre_exec() override
;
1586 void execute() override
;
1588 virtual int get_params() = 0;
1589 void send_response() override
= 0;
1590 const string
name() override
{ return "init_multipart"; }
1591 RGWOpType
get_type() override
{ return RGW_OP_INIT_MULTIPART
; }
1592 uint32_t op_mask() override
{ return RGW_OP_TYPE_WRITE
; }
1593 virtual int prepare_encryption(map
<string
, bufferlist
>& attrs
) { return 0; }
1596 class RGWCompleteMultipart
: public RGWOp
{
1603 struct MPSerializer
{
1604 librados::IoCtx ioctx
;
1605 rados::cls::lock::Lock lock
;
1606 librados::ObjectWriteOperation op
;
1610 MPSerializer() : lock("RGWCompleteMultipart"), locked(false)
1613 int try_lock(const std::string
& oid
, utime_t dur
);
1616 return lock
.unlock(&ioctx
, oid
);
1619 void clear_locked() {
1625 RGWCompleteMultipart() {
1629 ~RGWCompleteMultipart() override
{
1633 int verify_permission() override
;
1634 void pre_exec() override
;
1635 void execute() override
;
1636 void complete() override
;
1638 virtual int get_params() = 0;
1639 void send_response() override
= 0;
1640 const string
name() override
{ return "complete_multipart"; }
1641 RGWOpType
get_type() override
{ return RGW_OP_COMPLETE_MULTIPART
; }
1642 uint32_t op_mask() override
{ return RGW_OP_TYPE_WRITE
; }
1645 class RGWAbortMultipart
: public RGWOp
{
1647 RGWAbortMultipart() {}
1649 int verify_permission() override
;
1650 void pre_exec() override
;
1651 void execute() override
;
1653 void send_response() override
= 0;
1654 const string
name() override
{ return "abort_multipart"; }
1655 RGWOpType
get_type() override
{ return RGW_OP_ABORT_MULTIPART
; }
1656 uint32_t op_mask() override
{ return RGW_OP_TYPE_DELETE
; }
1659 class RGWListMultipart
: public RGWOp
{
1662 map
<uint32_t, RGWUploadPartInfo
> parts
;
1665 RGWAccessControlPolicy policy
;
1669 RGWListMultipart() {
1675 void init(RGWRados
*store
, struct req_state
*s
, RGWHandler
*h
) override
{
1676 RGWOp::init(store
, s
, h
);
1677 policy
= RGWAccessControlPolicy(s
->cct
);
1679 int verify_permission() override
;
1680 void pre_exec() override
;
1681 void execute() override
;
1683 virtual int get_params() = 0;
1684 void send_response() override
= 0;
1685 const string
name() override
{ return "list_multipart"; }
1686 RGWOpType
get_type() override
{ return RGW_OP_LIST_MULTIPART
; }
1687 uint32_t op_mask() override
{ return RGW_OP_TYPE_READ
; }
1690 struct RGWMultipartUploadEntry
{
1691 rgw_bucket_dir_entry obj
;
1695 class RGWListBucketMultiparts
: public RGWOp
{
1699 RGWMultipartUploadEntry next_marker
;
1702 vector
<RGWMultipartUploadEntry
> uploads
;
1703 map
<string
, bool> common_prefixes
;
1708 RGWListBucketMultiparts() {
1710 is_truncated
= false;
1714 void init(RGWRados
*store
, struct req_state
*s
, RGWHandler
*h
) override
{
1715 RGWOp::init(store
, s
, h
);
1716 max_uploads
= default_max
;
1719 int verify_permission() override
;
1720 void pre_exec() override
;
1721 void execute() override
;
1723 virtual int get_params() = 0;
1724 void send_response() override
= 0;
1725 const string
name() override
{ return "list_bucket_multiparts"; }
1726 RGWOpType
get_type() override
{ return RGW_OP_LIST_BUCKET_MULTIPARTS
; }
1727 uint32_t op_mask() override
{ return RGW_OP_TYPE_READ
; }
1731 class RGWGetCrossDomainPolicy
: public RGWOp
{
1733 RGWGetCrossDomainPolicy() = default;
1734 ~RGWGetCrossDomainPolicy() override
= default;
1736 int verify_permission() override
{
1740 void execute() override
{
1744 const string
name() override
{
1745 return "get_crossdomain_policy";
1748 RGWOpType
get_type() override
{
1749 return RGW_OP_GET_CROSS_DOMAIN_POLICY
;
1752 uint32_t op_mask() override
{
1753 return RGW_OP_TYPE_READ
;
1758 class RGWGetHealthCheck
: public RGWOp
{
1760 RGWGetHealthCheck() = default;
1761 ~RGWGetHealthCheck() override
= default;
1763 int verify_permission() override
{
1767 void execute() override
;
1769 const string
name() override
{
1770 return "get_health_check";
1773 RGWOpType
get_type() override
{
1774 return RGW_OP_GET_HEALTH_CHECK
;
1777 uint32_t op_mask() override
{
1778 return RGW_OP_TYPE_READ
;
1783 class RGWDeleteMultiObj
: public RGWOp
{
1791 bool acl_allowed
= false;
1794 RGWDeleteMultiObj() {
1795 max_to_delete
= 1000;
1799 status_dumped
= false;
1801 int verify_permission() override
;
1802 void pre_exec() override
;
1803 void execute() override
;
1805 virtual int get_params() = 0;
1806 virtual void send_status() = 0;
1807 virtual void begin_response() = 0;
1808 virtual void send_partial_response(rgw_obj_key
& key
, bool delete_marker
,
1809 const string
& marker_version_id
, int ret
) = 0;
1810 virtual void end_response() = 0;
1811 const string
name() override
{ return "multi_object_delete"; }
1812 RGWOpType
get_type() override
{ return RGW_OP_DELETE_MULTI_OBJ
; }
1813 uint32_t op_mask() override
{ return RGW_OP_TYPE_DELETE
; }
1816 class RGWInfo
: public RGWOp
{
1818 RGWInfo() = default;
1819 ~RGWInfo() override
= default;
1821 int verify_permission() override
{ return 0; }
1822 const string
name() override
{ return "get info"; }
1823 RGWOpType
get_type() override
{ return RGW_OP_GET_INFO
; }
1824 uint32_t op_mask() override
{ return RGW_OP_TYPE_READ
; }
1827 extern int rgw_build_bucket_policies(RGWRados
* store
, struct req_state
* s
);
1828 extern int rgw_build_object_policies(RGWRados
*store
, struct req_state
*s
,
1829 bool prefetch_data
);
1830 extern rgw::IAM::Environment
rgw_build_iam_environment(RGWRados
* store
,
1831 struct req_state
* s
);
1833 static inline int put_data_and_throttle(RGWPutObjDataProcessor
*processor
,
1834 bufferlist
& data
, off_t ofs
,
1839 void *handle
= nullptr;
1842 uint64_t size
= data
.length();
1844 int ret
= processor
->handle_data(data
, ofs
, &handle
, &obj
, &again
);
1847 if (handle
!= nullptr)
1849 ret
= processor
->throttle_data(handle
, obj
, size
, need_to_wait
);
1855 need_to_wait
= false; /* the need to wait only applies to the first
1860 } /* put_data_and_throttle */
1866 static inline int get_system_versioning_params(req_state
*s
,
1867 uint64_t *olh_epoch
,
1870 if (!s
->system_request
) {
1875 string epoch_str
= s
->info
.args
.get(RGW_SYS_PARAM_PREFIX
"versioned-epoch");
1876 if (!epoch_str
.empty()) {
1878 *olh_epoch
= strict_strtol(epoch_str
.c_str(), 10, &err
);
1880 lsubdout(s
->cct
, rgw
, 0) << "failed to parse versioned-epoch param"
1888 *version_id
= s
->info
.args
.get(RGW_SYS_PARAM_PREFIX
"version-id");
1892 } /* get_system_versioning_params */
1894 static inline void format_xattr(std::string
&xattr
)
1896 /* If the extended attribute is not valid UTF-8, we encode it using
1897 * quoted-printable encoding.
1899 if ((check_utf8(xattr
.c_str(), xattr
.length()) != 0) ||
1900 (check_for_control_characters(xattr
.c_str(), xattr
.length()) != 0)) {
1901 static const char MIME_PREFIX_STR
[] = "=?UTF-8?Q?";
1902 static const int MIME_PREFIX_LEN
= sizeof(MIME_PREFIX_STR
) - 1;
1903 static const char MIME_SUFFIX_STR
[] = "?=";
1904 static const int MIME_SUFFIX_LEN
= sizeof(MIME_SUFFIX_STR
) - 1;
1905 int mlen
= mime_encode_as_qp(xattr
.c_str(), NULL
, 0);
1906 char *mime
= new char[MIME_PREFIX_LEN
+ mlen
+ MIME_SUFFIX_LEN
+ 1];
1907 strcpy(mime
, MIME_PREFIX_STR
);
1908 mime_encode_as_qp(xattr
.c_str(), mime
+ MIME_PREFIX_LEN
, mlen
);
1909 strcpy(mime
+ MIME_PREFIX_LEN
+ (mlen
- 1), MIME_SUFFIX_STR
);
1913 } /* format_xattr */
1916 * Get the HTTP request metadata out of the req_state as a
1917 * map(<attr_name, attr_contents>, where attr_name is RGW_ATTR_PREFIX.HTTP_NAME)
1918 * s: The request state
1919 * attrs: will be filled up with attrs mapped as <attr_name, attr_contents>
1920 * On success returns 0.
1921 * On failure returns a negative error code.
1924 static inline int rgw_get_request_metadata(CephContext
* const cct
,
1925 struct req_info
& info
,
1926 std::map
<std::string
, ceph::bufferlist
>& attrs
,
1927 const bool allow_empty_attrs
= true)
1929 static const std::set
<std::string
> blacklisted_headers
= {
1930 "x-amz-server-side-encryption-customer-algorithm",
1931 "x-amz-server-side-encryption-customer-key",
1932 "x-amz-server-side-encryption-customer-key-md5"
1935 size_t valid_meta_count
= 0;
1936 for (auto& kv
: info
.x_meta_map
) {
1937 const std::string
& name
= kv
.first
;
1938 std::string
& xattr
= kv
.second
;
1940 if (blacklisted_headers
.count(name
) == 1) {
1941 lsubdout(cct
, rgw
, 10) << "skipping x>> " << name
<< dendl
;
1943 } else if (allow_empty_attrs
|| !xattr
.empty()) {
1944 lsubdout(cct
, rgw
, 10) << "x>> " << name
<< ":" << xattr
<< dendl
;
1945 format_xattr(xattr
);
1947 std::string
attr_name(RGW_ATTR_PREFIX
);
1948 attr_name
.append(name
);
1950 /* Check roughly whether we aren't going behind the limit on attribute
1951 * name. Passing here doesn't guarantee that an OSD will accept that
1952 * as ObjectStore::get_max_attr_name_length() can set the limit even
1953 * lower than the "osd_max_attr_name_len" configurable. */
1954 const size_t max_attr_name_len
= \
1955 cct
->_conf
->get_val
<size_t>("rgw_max_attr_name_len");
1956 if (max_attr_name_len
&& attr_name
.length() > max_attr_name_len
) {
1957 return -ENAMETOOLONG
;
1960 /* Similar remarks apply to the check for value size. We're veryfing
1961 * it early at the RGW's side as it's being claimed in /info. */
1962 const size_t max_attr_size
= \
1963 cct
->_conf
->get_val
<size_t>("rgw_max_attr_size");
1964 if (max_attr_size
&& xattr
.length() > max_attr_size
) {
1968 /* Swift allows administrators to limit the number of metadats items
1969 * send _in a single request_. */
1970 const auto rgw_max_attrs_num_in_req
= \
1971 cct
->_conf
->get_val
<size_t>("rgw_max_attrs_num_in_req");
1972 if (rgw_max_attrs_num_in_req
&&
1973 ++valid_meta_count
> rgw_max_attrs_num_in_req
) {
1977 auto rval
= attrs
.emplace(std::move(attr_name
), ceph::bufferlist());
1978 /* At the moment the value of the freshly created attribute key-value
1979 * pair is an empty bufferlist. */
1981 ceph::bufferlist
& bl
= rval
.first
->second
;
1982 bl
.append(xattr
.c_str(), xattr
.size() + 1);
1987 } /* rgw_get_request_metadata */
1989 static inline void encode_delete_at_attr(boost::optional
<ceph::real_time
> delete_at
,
1990 map
<string
, bufferlist
>& attrs
)
1992 if (delete_at
== boost::none
) {
1997 ::encode(*delete_at
, delatbl
);
1998 attrs
[RGW_ATTR_DELETE_AT
] = delatbl
;
1999 } /* encode_delete_at_attr */
2001 static inline void encode_obj_tags_attr(RGWObjTags
* obj_tags
, map
<string
, bufferlist
>& attrs
)
2003 if (obj_tags
== nullptr){
2004 // we assume the user submitted a tag format which we couldn't parse since
2005 // this wouldn't be parsed later by get/put obj tags, lets delete if the
2006 // attr was populated
2011 obj_tags
->encode(tagsbl
);
2012 attrs
[RGW_ATTR_TAGS
] = tagsbl
;
2015 static inline int encode_dlo_manifest_attr(const char * const dlo_manifest
,
2016 map
<string
, bufferlist
>& attrs
)
2018 string dm
= dlo_manifest
;
2020 if (dm
.find('/') == string::npos
) {
2024 bufferlist manifest_bl
;
2025 manifest_bl
.append(dlo_manifest
, strlen(dlo_manifest
) + 1);
2026 attrs
[RGW_ATTR_USER_MANIFEST
] = manifest_bl
;
2029 } /* encode_dlo_manifest_attr */
2031 static inline void complete_etag(MD5
& hash
, string
*etag
)
2033 char etag_buf
[CEPH_CRYPTO_MD5_DIGESTSIZE
];
2034 char etag_buf_str
[CEPH_CRYPTO_MD5_DIGESTSIZE
* 2 + 16];
2036 hash
.Final((byte
*)etag_buf
);
2037 buf_to_hex((const unsigned char *)etag_buf
, CEPH_CRYPTO_MD5_DIGESTSIZE
,
2040 *etag
= etag_buf_str
;
2041 } /* complete_etag */
2043 class RGWSetAttrs
: public RGWOp
{
2045 map
<string
, buffer::list
> attrs
;
2049 ~RGWSetAttrs() override
{}
2051 void emplace_attr(std::string
&& key
, buffer::list
&& bl
) {
2052 attrs
.emplace(std::move(key
), std::move(bl
));
2055 int verify_permission() override
;
2056 void pre_exec() override
;
2057 void execute() override
;
2059 virtual int get_params() = 0;
2060 void send_response() override
= 0;
2061 const string
name() override
{ return "set_attrs"; }
2062 RGWOpType
get_type() override
{ return RGW_OP_SET_ATTRS
; }
2063 uint32_t op_mask() override
{ return RGW_OP_TYPE_WRITE
; }
2066 class RGWGetObjLayout
: public RGWOp
{
2068 RGWObjManifest
*manifest
{nullptr};
2069 rgw_raw_obj head_obj
;
2075 int check_caps(RGWUserCaps
& caps
) {
2076 return caps
.check_cap("admin", RGW_CAP_READ
);
2078 int verify_permission() {
2079 return check_caps(s
->user
->caps
);
2084 virtual void send_response() = 0;
2085 virtual const string
name() { return "get_obj_layout"; }
2086 virtual RGWOpType
get_type() { return RGW_OP_GET_OBJ_LAYOUT
; }
2087 virtual uint32_t op_mask() { return RGW_OP_TYPE_READ
; }
2090 class RGWPutBucketPolicy
: public RGWOp
{
2092 char *data
= nullptr;
2094 RGWPutBucketPolicy() = default;
2095 ~RGWPutBucketPolicy() {
2097 free(static_cast<void*>(data
));
2100 void send_response() override
;
2101 int verify_permission() override
;
2102 uint32_t op_mask() override
{
2103 return RGW_OP_TYPE_WRITE
;
2105 void execute() override
;
2107 const std::string
name() override
{
2108 return "put_bucket_policy";
2110 RGWOpType
get_type() override
{
2111 return RGW_OP_PUT_BUCKET_POLICY
;
2115 class RGWGetBucketPolicy
: public RGWOp
{
2116 buffer::list policy
;
2118 RGWGetBucketPolicy() = default;
2119 void send_response() override
;
2120 int verify_permission() override
;
2121 uint32_t op_mask() override
{
2122 return RGW_OP_TYPE_READ
;
2124 void execute() override
;
2125 const std::string
name() override
{
2126 return "get_bucket_policy";
2128 RGWOpType
get_type() override
{
2129 return RGW_OP_GET_BUCKET_POLICY
;
2133 class RGWDeleteBucketPolicy
: public RGWOp
{
2135 RGWDeleteBucketPolicy() = default;
2136 void send_response() override
;
2137 int verify_permission() override
;
2138 uint32_t op_mask() override
{
2139 return RGW_OP_TYPE_WRITE
;
2141 void execute() override
;
2143 const std::string
name() override
{
2144 return "delete_bucket_policy";
2146 RGWOpType
get_type() override
{
2147 return RGW_OP_DELETE_BUCKET_POLICY
;
2152 class RGWConfigBucketMetaSearch
: public RGWOp
{
2154 std::map
<std::string
, uint32_t> mdsearch_config
;
2156 RGWConfigBucketMetaSearch() {}
2158 int verify_permission();
2162 virtual int get_params() = 0;
2163 virtual void send_response() = 0;
2164 virtual const string
name() { return "config_bucket_meta_search"; }
2165 virtual RGWOpType
get_type() { return RGW_OP_CONFIG_BUCKET_META_SEARCH
; }
2166 virtual uint32_t op_mask() { return RGW_OP_TYPE_WRITE
; }
2169 class RGWGetBucketMetaSearch
: public RGWOp
{
2171 RGWGetBucketMetaSearch() {}
2173 int verify_permission();
2177 virtual void send_response() = 0;
2178 virtual const string
name() { return "get_bucket_meta_search"; }
2179 virtual RGWOpType
get_type() { return RGW_OP_GET_BUCKET_META_SEARCH
; }
2180 virtual uint32_t op_mask() { return RGW_OP_TYPE_READ
; }
2183 class RGWDelBucketMetaSearch
: public RGWOp
{
2185 RGWDelBucketMetaSearch() {}
2187 int verify_permission();
2191 virtual void send_response() = 0;
2192 virtual const string
name() { return "delete_bucket_meta_search"; }
2193 virtual RGWOpType
delete_type() { return RGW_OP_DEL_BUCKET_META_SEARCH
; }
2194 virtual uint32_t op_mask() { return RGW_OP_TYPE_WRITE
; }
2197 #endif /* CEPH_RGW_OP_H */