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 "include/assert.h"
47 using ceph::crypto::SHA1
;
57 class StrategyRegistry
;
69 int do_init_permissions();
70 int do_read_permissions(RGWOp
* op
, bool only_bucket
);
77 virtual ~RGWHandler();
79 virtual int init(RGWRados
* store
,
81 rgw::io::BasicClient
* cio
);
83 virtual int init_permissions(RGWOp
*) {
87 virtual int retarget(RGWOp
* op
, RGWOp
** new_op
) {
92 virtual int read_permissions(RGWOp
* op
) = 0;
93 virtual int authorize() = 0;
94 virtual int postauth_init() = 0;
95 virtual int error_handler(int err_no
, std::string
* error_content
);
96 virtual void dump(const string
& code
, const string
& message
) const {}
101 void rgw_bucket_object_pre_exec(struct req_state
*s
);
104 * Provide the base class for all ops.
109 RGWHandler
*dialect_handler
;
111 RGWCORSConfiguration bucket_cors
;
113 RGWQuotaInfo bucket_quota
;
114 RGWQuotaInfo user_quota
;
117 int do_aws4_auth_completion();
119 virtual int init_quota();
123 dialect_handler(nullptr),
129 virtual ~RGWOp() = default;
131 int get_ret() const { return op_ret
; }
133 virtual int init_processing() {
134 op_ret
= init_quota();
141 virtual void init(RGWRados
*store
, struct req_state
*s
, RGWHandler
*dialect_handler
) {
144 this->dialect_handler
= dialect_handler
;
146 int read_bucket_cors();
147 bool generate_cors_headers(string
& origin
, string
& method
, string
& headers
, string
& exp_headers
, unsigned *max_age
);
149 virtual int verify_params() { return 0; }
150 virtual bool prefetch_data() { return false; }
152 /* Authenticate requester -- verify its identity.
154 * NOTE: typically the procedure is common across all operations of the same
155 * dialect (S3, Swift API). However, there are significant exceptions in
156 * both APIs: browser uploads, /info and OPTIONS handlers. All of them use
157 * different, specific authentication schema driving the need for per-op
158 * authentication. The alternative is to duplicate parts of the method-
159 * dispatch logic in RGWHandler::authorize() and pollute it with a lot
160 * of special cases. */
161 virtual int verify_requester(const rgw::auth::StrategyRegistry
& auth_registry
) {
162 /* TODO(rzarzynski): rename RGWHandler::authorize to generic_authenticate. */
163 return dialect_handler
->authorize();
165 virtual int verify_permission() = 0;
166 virtual int verify_op_mask();
167 virtual void pre_exec() {}
168 virtual void execute() = 0;
169 virtual void send_response() {}
170 virtual void complete() {
173 virtual const string
name() = 0;
174 virtual RGWOpType
get_type() { return RGW_OP_UNKNOWN
; }
176 virtual uint32_t op_mask() { return 0; }
178 virtual int error_handler(int err_no
, string
*error_content
);
181 class RGWGetObj
: public RGWOp
{
183 seed torrent
; // get torrent
184 const char *range_str
;
186 const char *if_unmod
;
187 const char *if_match
;
188 const char *if_nomatch
;
189 uint32_t mod_zone_id
;
195 ceph::real_time mod_time
;
196 ceph::real_time lastmod
;
197 ceph::real_time unmod_time
;
198 ceph::real_time
*mod_ptr
;
199 ceph::real_time
*unmod_ptr
;
200 map
<string
, bufferlist
> attrs
;
202 bool partial_content
;
206 utime_t gc_invalidate_time
;
209 bool rgwx_stat
; /* extended rgw stat operation */
213 RGWCompressionInfo cs_info
;
214 off_t first_block
, last_block
;
238 partial_content
= false;
239 range_parsed
= false;
240 skip_manifest
= false;
250 bool prefetch_data() override
;
252 void set_get_data(bool get_data
) {
253 this->get_data
= get_data
;
255 int verify_permission() override
;
256 void pre_exec() override
;
257 void execute() override
;
258 int read_user_manifest_part(
260 const rgw_bucket_dir_entry
& ent
,
261 RGWAccessControlPolicy
* const bucket_acl
,
262 const boost::optional
<rgw::IAM::Policy
>& bucket_policy
,
263 const off_t start_ofs
,
264 const off_t end_ofs
);
265 int handle_user_manifest(const char *prefix
);
266 int handle_slo_manifest(bufferlist
& bl
);
268 int get_data_cb(bufferlist
& bl
, off_t ofs
, off_t len
);
270 virtual int get_params() = 0;
271 virtual int send_response_data_error() = 0;
272 virtual int send_response_data(bufferlist
& bl
, off_t ofs
, off_t len
) = 0;
274 const string
name() override
{ return "get_obj"; }
275 RGWOpType
get_type() override
{ return RGW_OP_GET_OBJ
; }
276 uint32_t op_mask() override
{ return RGW_OP_TYPE_READ
; }
277 virtual bool need_object_expiration() { return false; }
279 * calculates filter used to decrypt RGW objects data
281 virtual int get_decrypt_filter(std::unique_ptr
<RGWGetDataCB
>* filter
, RGWGetDataCB
* cb
, bufferlist
* manifest_bl
) {
287 class RGWGetObj_CB
: public RGWGetDataCB
291 explicit RGWGetObj_CB(RGWGetObj
*_op
) : op(_op
) {}
292 ~RGWGetObj_CB() override
{}
294 int handle_data(bufferlist
& bl
, off_t bl_ofs
, off_t bl_len
) override
{
295 return op
->get_data_cb(bl
, bl_ofs
, bl_len
);
299 class RGWGetObj_Filter
: public RGWGetDataCB
304 RGWGetObj_Filter(RGWGetDataCB
* next
): next(next
) {}
305 ~RGWGetObj_Filter() override
{}
307 * Passes data through filter.
308 * Filter can modify content of bl.
309 * When bl_len == 0 , it means 'flush
311 int handle_data(bufferlist
& bl
, off_t bl_ofs
, off_t bl_len
) override
{
312 return next
->handle_data(bl
, bl_ofs
, bl_len
);
315 * Flushes any cached data. Used by RGWGetObjFilter.
316 * Return logic same as handle_data.
318 int flush() override
{
319 return next
->flush();
322 * Allows filter to extend range required for successful filtering
324 int fixup_range(off_t
& ofs
, off_t
& end
) override
{
325 return next
->fixup_range(ofs
, end
);
329 class RGWBulkDelete
: public RGWOp
{
332 std::string bucket_name
;
343 unsigned int num_deleted
;
344 unsigned int num_unfound
;
345 std::list
<fail_desc_t
> failures
;
347 RGWRados
* const store
;
351 Deleter(RGWRados
* const str
, req_state
* const s
)
358 unsigned int get_num_deleted() const {
362 unsigned int get_num_unfound() const {
366 const std::list
<fail_desc_t
> get_failures() const {
370 bool verify_permission(RGWBucketInfo
& binfo
,
371 map
<string
, bufferlist
>& battrs
,
372 ACLOwner
& bucket_owner
/* out */);
373 bool delete_single(const acct_path_t
& path
);
374 bool delete_chunk(const std::list
<acct_path_t
>& paths
);
376 /* End of Deleter subclass */
378 static const size_t MAX_CHUNK_ENTRIES
= 1024;
381 std::unique_ptr
<Deleter
> deleter
;
388 int verify_permission() override
;
389 void pre_exec() override
;
390 void execute() override
;
392 virtual int get_data(std::list
<acct_path_t
>& items
,
393 bool * is_truncated
) = 0;
394 void send_response() override
= 0;
396 const string
name() override
{ return "bulk_delete"; }
397 RGWOpType
get_type() override
{ return RGW_OP_BULK_DELETE
; }
398 uint32_t op_mask() override
{ return RGW_OP_TYPE_DELETE
; }
401 inline ostream
& operator<<(ostream
& out
, const RGWBulkDelete::acct_path_t
&o
) {
402 return out
<< o
.bucket_name
<< "/" << o
.obj_key
;
406 class RGWBulkUploadOp
: public RGWOp
{
407 boost::optional
<RGWObjectCtx
> dir_ctx
;
412 fail_desc_t(const int err
, std::string path
)
414 path(std::move(path
)) {
418 const std::string path
;
421 static constexpr std::array
<int, 2> terminal_errors
= {
425 /* FIXME: boost::container::small_vector<fail_desc_t, 4> failures; */
426 std::vector
<fail_desc_t
> failures
;
430 class DecoratedStreamGetter
;
431 class AlignedStreamGetter
;
433 virtual std::unique_ptr
<StreamGetter
> create_stream() = 0;
434 virtual void send_response() = 0;
436 boost::optional
<std::pair
<std::string
, rgw_obj_key
>>
437 parse_path(const boost::string_ref
& path
);
439 std::pair
<std::string
, std::string
>
440 handle_upload_path(struct req_state
*s
);
442 bool handle_file_verify_permission(RGWBucketInfo
& binfo
,
444 std::map
<std::string
, ceph::bufferlist
>& battrs
,
445 ACLOwner
& bucket_owner
/* out */);
446 int handle_file(boost::string_ref path
,
448 AlignedStreamGetter
& body
);
450 int handle_dir_verify_permission();
451 int handle_dir(boost::string_ref path
);
458 void init(RGWRados
* const store
,
459 struct req_state
* const s
,
460 RGWHandler
* const h
) override
{
461 RGWOp::init(store
, s
, h
);
462 dir_ctx
.emplace(store
);
465 int verify_permission() override
;
466 void pre_exec() override
;
467 void execute() override
;
469 const std::string
name() override
{
470 return "bulk_upload";
473 RGWOpType
get_type() override
{
474 return RGW_OP_BULK_UPLOAD
;
477 uint32_t op_mask() override
{
478 return RGW_OP_TYPE_WRITE
;
480 }; /* RGWBulkUploadOp */
483 class RGWBulkUploadOp::StreamGetter
{
485 StreamGetter() = default;
486 virtual ~StreamGetter() = default;
488 virtual ssize_t
get_at_most(size_t want
, ceph::bufferlist
& dst
) = 0;
489 virtual ssize_t
get_exactly(size_t want
, ceph::bufferlist
& dst
) = 0;
490 }; /* End of nested subclass StreamGetter */
493 class RGWBulkUploadOp::DecoratedStreamGetter
: public StreamGetter
{
494 StreamGetter
& decoratee
;
497 StreamGetter
& get_decoratee() {
502 DecoratedStreamGetter(StreamGetter
& decoratee
)
503 : decoratee(decoratee
) {
505 virtual ~DecoratedStreamGetter() = default;
507 ssize_t
get_at_most(const size_t want
, ceph::bufferlist
& dst
) override
{
508 return get_decoratee().get_at_most(want
, dst
);
511 ssize_t
get_exactly(const size_t want
, ceph::bufferlist
& dst
) override
{
512 return get_decoratee().get_exactly(want
, dst
);
514 }; /* RGWBulkUploadOp::DecoratedStreamGetter */
517 class RGWBulkUploadOp::AlignedStreamGetter
518 : public RGWBulkUploadOp::DecoratedStreamGetter
{
524 template <typename U
>
525 AlignedStreamGetter(const size_t position
,
527 const size_t alignment
,
529 : DecoratedStreamGetter(std::forward
<U
>(decoratee
)),
532 alignment(alignment
) {
534 virtual ~AlignedStreamGetter();
535 ssize_t
get_at_most(size_t want
, ceph::bufferlist
& dst
) override
;
536 ssize_t
get_exactly(size_t want
, ceph::bufferlist
& dst
) override
;
537 }; /* RGWBulkUploadOp::AlignedStreamGetter */
540 #define RGW_LIST_BUCKETS_LIMIT_MAX 10000
542 class RGWListBuckets
: public RGWOp
{
549 uint32_t buckets_count
;
550 uint64_t buckets_objcount
;
551 uint64_t buckets_size
;
552 uint64_t buckets_size_rounded
;
553 map
<string
, bufferlist
> attrs
;
556 virtual uint64_t get_default_max() const {
561 RGWListBuckets() : sent_data(false) {
562 limit
= limit_max
= RGW_LIST_BUCKETS_LIMIT_MAX
;
564 buckets_objcount
= 0;
566 buckets_size_rounded
= 0;
567 is_truncated
= false;
570 int verify_permission() override
;
571 void execute() override
;
573 virtual int get_params() = 0;
574 virtual void send_response_begin(bool has_buckets
) = 0;
575 virtual void send_response_data(RGWUserBuckets
& buckets
) = 0;
576 virtual void send_response_end() = 0;
577 void send_response() override
{}
579 virtual bool should_get_stats() { return false; }
580 virtual bool supports_account_metadata() { return false; }
582 const string
name() override
{ return "list_buckets"; }
583 RGWOpType
get_type() override
{ return RGW_OP_LIST_BUCKETS
; }
584 uint32_t op_mask() override
{ return RGW_OP_TYPE_READ
; }
587 class RGWGetUsage
: public RGWOp
{
592 int show_log_entries
;
594 map
<string
, bool> categories
;
595 map
<rgw_user_bucket
, rgw_usage_log_entry
> usage
;
596 map
<string
, rgw_usage_log_entry
> summary_map
;
597 cls_user_header header
;
599 RGWGetUsage() : sent_data(false), show_log_entries(true), show_log_sum(true){
602 int verify_permission() override
;
603 void execute() override
;
605 virtual int get_params() = 0;
606 void send_response() override
{}
608 virtual bool should_get_stats() { return false; }
610 const string
name() override
{ return "get_usage"; }
611 uint32_t op_mask() override
{ return RGW_OP_TYPE_READ
; }
614 class RGWStatAccount
: public RGWOp
{
616 uint32_t buckets_count
;
617 uint64_t buckets_objcount
;
618 uint64_t buckets_size
;
619 uint64_t buckets_size_rounded
;
624 buckets_objcount
= 0;
626 buckets_size_rounded
= 0;
629 int verify_permission() override
;
630 void execute() override
;
632 void send_response() override
= 0;
633 const string
name() override
{ return "stat_account"; }
634 RGWOpType
get_type() override
{ return RGW_OP_STAT_ACCOUNT
; }
635 uint32_t op_mask() override
{ return RGW_OP_TYPE_READ
; }
638 class RGWListBucket
: public RGWOp
{
643 rgw_obj_key next_marker
;
644 rgw_obj_key end_marker
;
647 string encoding_type
;
650 vector
<rgw_bucket_dir_entry
> objs
;
651 map
<string
, bool> common_prefixes
;
658 int parse_max_keys();
661 RGWListBucket() : list_versions(false), max(0),
662 default_max(0), is_truncated(false), shard_id(-1) {}
663 int verify_permission() override
;
664 void pre_exec() override
;
665 void execute() override
;
667 virtual int get_params() = 0;
668 void send_response() override
= 0;
669 const string
name() override
{ return "list_bucket"; }
670 RGWOpType
get_type() override
{ return RGW_OP_LIST_BUCKET
; }
671 uint32_t op_mask() override
{ return RGW_OP_TYPE_READ
; }
672 virtual bool need_container_stats() { return false; }
675 class RGWGetBucketLogging
: public RGWOp
{
677 RGWGetBucketLogging() {}
678 int verify_permission() override
;
679 void execute() override
{ }
681 void send_response() override
= 0;
682 const string
name() override
{ return "get_bucket_logging"; }
683 RGWOpType
get_type() override
{ return RGW_OP_GET_BUCKET_LOGGING
; }
684 uint32_t op_mask() override
{ return RGW_OP_TYPE_READ
; }
687 class RGWGetBucketLocation
: public RGWOp
{
689 RGWGetBucketLocation() {}
690 ~RGWGetBucketLocation() override
{}
691 int verify_permission() override
;
692 void execute() override
{ }
694 void send_response() override
= 0;
695 const string
name() override
{ return "get_bucket_location"; }
696 uint32_t op_mask() override
{ return RGW_OP_TYPE_READ
; }
699 class RGWGetBucketVersioning
: public RGWOp
{
702 bool versioning_enabled
;
704 RGWGetBucketVersioning() : versioned(false), versioning_enabled(false) {}
706 int verify_permission() override
;
707 void pre_exec() override
;
708 void execute() override
;
710 void send_response() override
= 0;
711 const string
name() override
{ return "get_bucket_versioning"; }
712 RGWOpType
get_type() override
{ return RGW_OP_GET_BUCKET_VERSIONING
; }
713 uint32_t op_mask() override
{ return RGW_OP_TYPE_READ
; }
716 class RGWSetBucketVersioning
: public RGWOp
{
718 bool enable_versioning
;
721 RGWSetBucketVersioning() : enable_versioning(false) {}
723 int verify_permission() override
;
724 void pre_exec() override
;
725 void execute() override
;
727 virtual int get_params() { return 0; }
729 void send_response() override
= 0;
730 const string
name() override
{ return "set_bucket_versioning"; }
731 RGWOpType
get_type() override
{ return RGW_OP_SET_BUCKET_VERSIONING
; }
732 uint32_t op_mask() override
{ return RGW_OP_TYPE_WRITE
; }
735 class RGWGetBucketWebsite
: public RGWOp
{
737 RGWGetBucketWebsite() {}
739 int verify_permission() override
;
740 void pre_exec() override
;
741 void execute() override
;
743 void send_response() override
= 0;
744 const string
name() override
{ return "get_bucket_website"; }
745 RGWOpType
get_type() override
{ return RGW_OP_GET_BUCKET_WEBSITE
; }
746 uint32_t op_mask() override
{ return RGW_OP_TYPE_READ
; }
749 class RGWSetBucketWebsite
: public RGWOp
{
752 RGWBucketWebsiteConf website_conf
;
754 RGWSetBucketWebsite() {}
756 int verify_permission() override
;
757 void pre_exec() override
;
758 void execute() override
;
760 virtual int get_params() { return 0; }
762 void send_response() override
= 0;
763 const string
name() override
{ return "set_bucket_website"; }
764 RGWOpType
get_type() override
{ return RGW_OP_SET_BUCKET_WEBSITE
; }
765 uint32_t op_mask() override
{ return RGW_OP_TYPE_WRITE
; }
768 class RGWDeleteBucketWebsite
: public RGWOp
{
770 RGWDeleteBucketWebsite() {}
772 int verify_permission() override
;
773 void pre_exec() override
;
774 void execute() override
;
776 void send_response() override
= 0;
777 const string
name() override
{ return "delete_bucket_website"; }
778 RGWOpType
get_type() override
{ return RGW_OP_SET_BUCKET_WEBSITE
; }
779 uint32_t op_mask() override
{ return RGW_OP_TYPE_WRITE
; }
782 class RGWStatBucket
: public RGWOp
{
788 ~RGWStatBucket() override
{}
790 int verify_permission() override
;
791 void pre_exec() override
;
792 void execute() override
;
794 void send_response() override
= 0;
795 const string
name() override
{ return "stat_bucket"; }
796 RGWOpType
get_type() override
{ return RGW_OP_STAT_BUCKET
; }
797 uint32_t op_mask() override
{ return RGW_OP_TYPE_READ
; }
800 class RGWCreateBucket
: public RGWOp
{
802 RGWAccessControlPolicy policy
;
803 string location_constraint
;
804 string placement_rule
;
808 RGWCORSConfiguration cors_config
;
809 boost::optional
<std::string
> swift_ver_location
;
810 map
<string
, buffer::list
> attrs
;
811 set
<string
> rmattr_names
;
815 virtual bool need_metadata_upload() const { return false; }
818 RGWCreateBucket() : has_cors(false) {}
820 void emplace_attr(std::string
&& key
, buffer::list
&& bl
) {
821 attrs
.emplace(std::move(key
), std::move(bl
)); /* key and bl are r-value refs */
824 int verify_permission() override
;
825 void pre_exec() override
;
826 void execute() override
;
827 void init(RGWRados
*store
, struct req_state
*s
, RGWHandler
*h
) override
{
828 RGWOp::init(store
, s
, h
);
829 policy
.set_ctx(s
->cct
);
831 virtual int get_params() { return 0; }
832 void send_response() override
= 0;
833 const string
name() override
{ return "create_bucket"; }
834 RGWOpType
get_type() override
{ return RGW_OP_CREATE_BUCKET
; }
835 uint32_t op_mask() override
{ return RGW_OP_TYPE_WRITE
; }
838 class RGWDeleteBucket
: public RGWOp
{
840 RGWObjVersionTracker objv_tracker
;
845 int verify_permission() override
;
846 void pre_exec() override
;
847 void execute() override
;
849 void send_response() override
= 0;
850 const string
name() override
{ return "delete_bucket"; }
851 RGWOpType
get_type() override
{ return RGW_OP_DELETE_BUCKET
; }
852 uint32_t op_mask() override
{ return RGW_OP_TYPE_DELETE
; }
855 struct rgw_slo_entry
{
860 rgw_slo_entry() : size_bytes(0) {}
862 void encode(bufferlist
& bl
) const {
863 ENCODE_START(1, 1, bl
);
866 ::encode(size_bytes
, bl
);
870 void decode(bufferlist::iterator
& bl
) {
874 ::decode(size_bytes
, bl
);
878 void decode_json(JSONObj
*obj
);
880 WRITE_CLASS_ENCODER(rgw_slo_entry
)
883 vector
<rgw_slo_entry
> entries
;
890 RGWSLOInfo() : total_size(0), raw_data(NULL
), raw_data_len(0) {}
895 void encode(bufferlist
& bl
) const {
896 ENCODE_START(1, 1, bl
);
897 ::encode(entries
, bl
);
898 ::encode(total_size
, bl
);
902 void decode(bufferlist::iterator
& bl
) {
904 ::decode(entries
, bl
);
905 ::decode(total_size
, bl
);
909 WRITE_CLASS_ENCODER(RGWSLOInfo
)
911 class RGWPutObj
: public RGWOp
{
913 friend class RGWPutObjProcessor
;
918 const char *supplied_md5_b64
;
919 const char *supplied_etag
;
920 const char *if_match
;
921 const char *if_nomatch
;
922 const char *copy_source
;
923 const char *copy_source_range
;
924 RGWBucketInfo copy_source_bucket_info
;
925 string copy_source_tenant_name
;
926 string copy_source_bucket_name
;
927 string copy_source_object_name
;
928 string copy_source_version_id
;
929 off_t copy_source_range_fst
;
930 off_t copy_source_range_lst
;
933 RGWAccessControlPolicy policy
;
934 const char *dlo_manifest
;
935 RGWSLOInfo
*slo_info
;
936 map
<string
, bufferlist
> attrs
;
937 ceph::real_time mtime
;
941 map
<string
, string
> crypt_http_responses
;
944 boost::optional
<ceph::real_time
> delete_at
;
947 RGWPutObj() : ofs(0),
948 supplied_md5_b64(NULL
),
953 copy_source_range(NULL
),
954 copy_source_range_fst(0),
955 copy_source_range_lst(0),
961 ~RGWPutObj() override
{
965 void init(RGWRados
*store
, struct req_state
*s
, RGWHandler
*h
) override
{
966 RGWOp::init(store
, s
, h
);
967 policy
.set_ctx(s
->cct
);
970 void emplace_attr(std::string
&& key
, buffer::list
&& bl
) {
971 attrs
.emplace(std::move(key
), std::move(bl
)); /* key and bl are r-value refs */
974 virtual RGWPutObjProcessor
*select_processor(RGWObjectCtx
& obj_ctx
, bool *is_multipart
);
975 void dispose_processor(RGWPutObjDataProcessor
*processor
);
977 int verify_permission() override
;
978 void pre_exec() override
;
979 void execute() override
;
981 /* this is for cases when copying data from other object */
982 virtual int get_decrypt_filter(std::unique_ptr
<RGWGetDataCB
>* filter
,
984 map
<string
, bufferlist
>& attrs
,
985 bufferlist
* manifest_bl
) {
989 virtual int get_encrypt_filter(std::unique_ptr
<RGWPutObjDataProcessor
> *filter
, RGWPutObjDataProcessor
* cb
) {
994 int get_data_cb(bufferlist
& bl
, off_t bl_ofs
, off_t bl_len
);
995 int get_data(const off_t fst
, const off_t lst
, bufferlist
& bl
);
997 virtual int get_params() = 0;
998 virtual int get_data(bufferlist
& bl
) = 0;
999 void send_response() override
= 0;
1000 const string
name() override
{ return "put_obj"; }
1001 RGWOpType
get_type() override
{ return RGW_OP_PUT_OBJ
; }
1002 uint32_t op_mask() override
{ return RGW_OP_TYPE_WRITE
; }
1005 class RGWPutObj_Filter
: public RGWPutObjDataProcessor
1008 RGWPutObjDataProcessor
* next
;
1010 RGWPutObj_Filter(RGWPutObjDataProcessor
* next
) :
1012 ~RGWPutObj_Filter() override
{}
1013 int handle_data(bufferlist
& bl
, off_t ofs
, void **phandle
, rgw_raw_obj
*pobj
, bool *again
) override
{
1014 return next
->handle_data(bl
, ofs
, phandle
, pobj
, again
);
1016 int throttle_data(void *handle
, const rgw_raw_obj
& obj
, uint64_t size
, bool need_to_wait
) override
{
1017 return next
->throttle_data(handle
, obj
, size
, need_to_wait
);
1019 }; /* RGWPutObj_Filter */
1021 class RGWPostObj
: public RGWOp
{
1027 const char *supplied_md5_b64
;
1028 const char *supplied_etag
;
1030 RGWAccessControlPolicy policy
;
1031 map
<string
, bufferlist
> attrs
;
1032 boost::optional
<ceph::real_time
> delete_at
;
1034 /* Must be called after get_data() or the result is undefined. */
1035 virtual std::string
get_current_filename() const = 0;
1036 virtual std::string
get_current_content_type() const = 0;
1037 virtual bool is_next_file_to_upload() {
1041 RGWPostObj() : min_len(0),
1045 supplied_md5_b64(nullptr),
1046 supplied_etag(nullptr) {
1049 void emplace_attr(std::string
&& key
, buffer::list
&& bl
) {
1050 attrs
.emplace(std::move(key
), std::move(bl
)); /* key and bl are r-value refs */
1053 void init(RGWRados
*store
, struct req_state
*s
, RGWHandler
*h
) override
{
1054 RGWOp::init(store
, s
, h
);
1055 policy
.set_ctx(s
->cct
);
1058 int verify_permission() override
;
1059 void pre_exec() override
;
1060 void execute() override
;
1062 virtual int get_encrypt_filter(std::unique_ptr
<RGWPutObjDataProcessor
> *filter
, RGWPutObjDataProcessor
* cb
) {
1066 virtual int get_params() = 0;
1067 virtual int get_data(ceph::bufferlist
& bl
, bool& again
) = 0;
1068 void send_response() override
= 0;
1069 const std::string
name() override
{ return "post_obj"; }
1070 RGWOpType
get_type() override
{ return RGW_OP_POST_OBJ
; }
1071 uint32_t op_mask() override
{ return RGW_OP_TYPE_WRITE
; }
1074 class RGWPutMetadataAccount
: public RGWOp
{
1076 std::set
<std::string
> rmattr_names
;
1077 std::map
<std::string
, bufferlist
> attrs
, orig_attrs
;
1078 std::map
<int, std::string
> temp_url_keys
;
1079 RGWQuotaInfo new_quota
;
1080 bool new_quota_extracted
;
1082 RGWObjVersionTracker acct_op_tracker
;
1084 RGWAccessControlPolicy policy
;
1088 RGWPutMetadataAccount()
1089 : new_quota_extracted(false),
1093 void init(RGWRados
*store
, struct req_state
*s
, RGWHandler
*h
) override
{
1094 RGWOp::init(store
, s
, h
);
1095 policy
.set_ctx(s
->cct
);
1097 int init_processing() override
;
1098 int verify_permission() override
;
1099 void pre_exec() override
{ }
1100 void execute() override
;
1102 virtual int get_params() = 0;
1103 void send_response() override
= 0;
1104 virtual void filter_out_temp_url(map
<string
, bufferlist
>& add_attrs
,
1105 const set
<string
>& rmattr_names
,
1106 map
<int, string
>& temp_url_keys
);
1107 const string
name() override
{ return "put_account_metadata"; }
1108 RGWOpType
get_type() override
{ return RGW_OP_PUT_METADATA_ACCOUNT
; }
1109 uint32_t op_mask() override
{ return RGW_OP_TYPE_WRITE
; }
1112 class RGWPutMetadataBucket
: public RGWOp
{
1114 map
<string
, buffer::list
> attrs
;
1115 set
<string
> rmattr_names
;
1116 bool has_policy
, has_cors
;
1117 uint32_t policy_rw_mask
;
1118 RGWAccessControlPolicy policy
;
1119 RGWCORSConfiguration cors_config
;
1120 string placement_rule
;
1121 boost::optional
<std::string
> swift_ver_location
;
1124 RGWPutMetadataBucket()
1125 : has_policy(false), has_cors(false), policy_rw_mask(0)
1128 void emplace_attr(std::string
&& key
, buffer::list
&& bl
) {
1129 attrs
.emplace(std::move(key
), std::move(bl
)); /* key and bl are r-value refs */
1132 void init(RGWRados
*store
, struct req_state
*s
, RGWHandler
*h
) override
{
1133 RGWOp::init(store
, s
, h
);
1134 policy
.set_ctx(s
->cct
);
1137 int verify_permission() override
;
1138 void pre_exec() override
;
1139 void execute() override
;
1141 virtual int get_params() = 0;
1142 void send_response() override
= 0;
1143 const string
name() override
{ return "put_bucket_metadata"; }
1144 RGWOpType
get_type() override
{ return RGW_OP_PUT_METADATA_BUCKET
; }
1145 uint32_t op_mask() override
{ return RGW_OP_TYPE_WRITE
; }
1148 class RGWPutMetadataObject
: public RGWOp
{
1150 RGWAccessControlPolicy policy
;
1151 string placement_rule
;
1152 boost::optional
<ceph::real_time
> delete_at
;
1153 const char *dlo_manifest
;
1156 RGWPutMetadataObject()
1157 : dlo_manifest(NULL
)
1160 void init(RGWRados
*store
, struct req_state
*s
, RGWHandler
*h
) override
{
1161 RGWOp::init(store
, s
, h
);
1162 policy
.set_ctx(s
->cct
);
1164 int verify_permission() override
;
1165 void pre_exec() override
;
1166 void execute() override
;
1168 virtual int get_params() = 0;
1169 void send_response() override
= 0;
1170 const string
name() override
{ return "put_obj_metadata"; }
1171 RGWOpType
get_type() override
{ return RGW_OP_PUT_METADATA_OBJECT
; }
1172 uint32_t op_mask() override
{ return RGW_OP_TYPE_WRITE
; }
1173 virtual bool need_object_expiration() { return false; }
1176 class RGWDeleteObj
: public RGWOp
{
1179 bool multipart_delete
;
1181 ceph::real_time unmod_since
; /* if unmodified since */
1182 bool no_precondition_error
;
1183 std::unique_ptr
<RGWBulkDelete::Deleter
> deleter
;
1187 : delete_marker(false),
1188 multipart_delete(false),
1189 no_precondition_error(false),
1193 int verify_permission() override
;
1194 void pre_exec() override
;
1195 void execute() override
;
1196 int handle_slo_manifest(bufferlist
& bl
);
1198 virtual int get_params() { return 0; }
1199 void send_response() override
= 0;
1200 const string
name() override
{ return "delete_obj"; }
1201 RGWOpType
get_type() override
{ return RGW_OP_DELETE_OBJ
; }
1202 uint32_t op_mask() override
{ return RGW_OP_TYPE_DELETE
; }
1203 virtual bool need_object_expiration() { return false; }
1206 class RGWCopyObj
: public RGWOp
{
1208 RGWAccessControlPolicy dest_policy
;
1210 const char *if_unmod
;
1211 const char *if_match
;
1212 const char *if_nomatch
;
1216 ceph::real_time mod_time
;
1217 ceph::real_time unmod_time
;
1218 ceph::real_time
*mod_ptr
;
1219 ceph::real_time
*unmod_ptr
;
1220 map
<string
, buffer::list
> attrs
;
1221 string src_tenant_name
, src_bucket_name
;
1222 rgw_bucket src_bucket
;
1223 rgw_obj_key src_object
;
1224 string dest_tenant_name
, dest_bucket_name
;
1225 rgw_bucket dest_bucket
;
1227 ceph::real_time src_mtime
;
1228 ceph::real_time mtime
;
1229 RGWRados::AttrsMod attrs_mod
;
1230 RGWBucketInfo src_bucket_info
;
1231 RGWBucketInfo dest_bucket_info
;
1235 ceph::buffer::list etag
;
1242 boost::optional
<ceph::real_time
> delete_at
;
1258 attrs_mod
= RGWRados::ATTRSMOD_NONE
;
1261 copy_if_newer
= false;
1264 static bool parse_copy_location(const string
& src
,
1265 string
& bucket_name
,
1266 rgw_obj_key
& object
);
1268 void emplace_attr(std::string
&& key
, buffer::list
&& bl
) {
1269 attrs
.emplace(std::move(key
), std::move(bl
));
1272 void init(RGWRados
*store
, struct req_state
*s
, RGWHandler
*h
) override
{
1273 RGWOp::init(store
, s
, h
);
1274 dest_policy
.set_ctx(s
->cct
);
1276 int verify_permission() override
;
1277 void pre_exec() override
;
1278 void execute() override
;
1279 void progress_cb(off_t ofs
);
1281 virtual int init_dest_policy() { return 0; }
1282 virtual int get_params() = 0;
1283 virtual void send_partial_response(off_t ofs
) {}
1284 void send_response() override
= 0;
1285 const string
name() override
{ return "copy_obj"; }
1286 RGWOpType
get_type() override
{ return RGW_OP_COPY_OBJ
; }
1287 uint32_t op_mask() override
{ return RGW_OP_TYPE_WRITE
; }
1290 class RGWGetACLs
: public RGWOp
{
1297 int verify_permission() override
;
1298 void pre_exec() override
;
1299 void execute() override
;
1301 void send_response() override
= 0;
1302 const string
name() override
{ return "get_acls"; }
1303 RGWOpType
get_type() override
{ return RGW_OP_GET_ACLS
; }
1304 uint32_t op_mask() override
{ return RGW_OP_TYPE_READ
; }
1307 class RGWPutACLs
: public RGWOp
{
1318 ~RGWPutACLs() override
{
1322 int verify_permission() override
;
1323 void pre_exec() override
;
1324 void execute() override
;
1326 virtual int get_policy_from_state(RGWRados
*store
, struct req_state
*s
, stringstream
& ss
) { return 0; }
1327 virtual int get_params() = 0;
1328 void send_response() override
= 0;
1329 const string
name() override
{ return "put_acls"; }
1330 RGWOpType
get_type() override
{ return RGW_OP_PUT_ACLS
; }
1331 uint32_t op_mask() override
{ return RGW_OP_TYPE_WRITE
; }
1334 class RGWGetLC
: public RGWOp
{
1339 ~RGWGetLC() override
{ }
1341 int verify_permission() override
;
1342 void pre_exec() override
;
1343 void execute() override
= 0;
1345 void send_response() override
= 0;
1346 const string
name() override
{ return "get_lifecycle"; }
1347 uint32_t op_mask() override
{ return RGW_OP_TYPE_READ
; }
1350 class RGWPutLC
: public RGWOp
{
1361 ~RGWPutLC() override
{
1365 void init(RGWRados
*store
, struct req_state
*s
, RGWHandler
*dialect_handler
) override
{
1366 #define COOKIE_LEN 16
1367 char buf
[COOKIE_LEN
+ 1];
1369 RGWOp::init(store
, s
, dialect_handler
);
1370 gen_rand_alphanumeric(s
->cct
, buf
, sizeof(buf
) - 1);
1374 int verify_permission() override
;
1375 void pre_exec() override
;
1376 void execute() override
;
1378 // virtual int get_policy_from_state(RGWRados *store, struct req_state *s, stringstream& ss) { return 0; }
1379 virtual int get_params() = 0;
1380 void send_response() override
= 0;
1381 const string
name() override
{ return "put_lifecycle"; }
1382 uint32_t op_mask() override
{ return RGW_OP_TYPE_WRITE
; }
1385 class RGWDeleteLC
: public RGWOp
{
1395 ~RGWDeleteLC() override
{
1399 int verify_permission() override
;
1400 void pre_exec() override
;
1401 void execute() override
;
1403 void send_response() override
= 0;
1404 const string
name() override
{ return "delete_lifecycle"; }
1405 uint32_t op_mask() override
{ return RGW_OP_TYPE_WRITE
; }
1408 class RGWGetCORS
: public RGWOp
{
1414 int verify_permission() override
;
1415 void execute() override
;
1417 void send_response() override
= 0;
1418 const string
name() override
{ return "get_cors"; }
1419 RGWOpType
get_type() override
{ return RGW_OP_GET_CORS
; }
1420 uint32_t op_mask() override
{ return RGW_OP_TYPE_READ
; }
1423 class RGWPutCORS
: public RGWOp
{
1430 ~RGWPutCORS() override
{}
1432 int verify_permission() override
;
1433 void execute() override
;
1435 virtual int get_params() = 0;
1436 void send_response() override
= 0;
1437 const string
name() override
{ return "put_cors"; }
1438 RGWOpType
get_type() override
{ return RGW_OP_PUT_CORS
; }
1439 uint32_t op_mask() override
{ return RGW_OP_TYPE_WRITE
; }
1442 class RGWDeleteCORS
: public RGWOp
{
1448 int verify_permission() override
;
1449 void execute() override
;
1451 void send_response() override
= 0;
1452 const string
name() override
{ return "delete_cors"; }
1453 RGWOpType
get_type() override
{ return RGW_OP_DELETE_CORS
; }
1454 uint32_t op_mask() override
{ return RGW_OP_TYPE_WRITE
; }
1457 class RGWOptionsCORS
: public RGWOp
{
1460 const char *origin
, *req_hdrs
, *req_meth
;
1463 RGWOptionsCORS() : rule(NULL
), origin(NULL
),
1464 req_hdrs(NULL
), req_meth(NULL
) {
1467 int verify_permission() override
{return 0;}
1468 int validate_cors_request(RGWCORSConfiguration
*cc
);
1469 void execute() override
;
1470 void get_response_params(string
& allowed_hdrs
, string
& exp_hdrs
, unsigned *max_age
);
1471 void send_response() override
= 0;
1472 const string
name() override
{ return "options_cors"; }
1473 RGWOpType
get_type() override
{ return RGW_OP_OPTIONS_CORS
; }
1474 uint32_t op_mask() override
{ return RGW_OP_TYPE_READ
; }
1477 class RGWGetRequestPayment
: public RGWOp
{
1479 bool requester_pays
;
1482 RGWGetRequestPayment() : requester_pays(0) {}
1484 int verify_permission() override
;
1485 void pre_exec() override
;
1486 void execute() override
;
1488 void send_response() override
= 0;
1489 const string
name() override
{ return "get_request_payment"; }
1490 RGWOpType
get_type() override
{ return RGW_OP_GET_REQUEST_PAYMENT
; }
1491 uint32_t op_mask() override
{ return RGW_OP_TYPE_READ
; }
1494 class RGWSetRequestPayment
: public RGWOp
{
1496 bool requester_pays
;
1498 RGWSetRequestPayment() : requester_pays(false) {}
1500 int verify_permission() override
;
1501 void pre_exec() override
;
1502 void execute() override
;
1504 virtual int get_params() { return 0; }
1506 void send_response() override
= 0;
1507 const string
name() override
{ return "set_request_payment"; }
1508 RGWOpType
get_type() override
{ return RGW_OP_SET_REQUEST_PAYMENT
; }
1509 uint32_t op_mask() override
{ return RGW_OP_TYPE_WRITE
; }
1512 class RGWInitMultipart
: public RGWOp
{
1515 RGWAccessControlPolicy policy
;
1518 RGWInitMultipart() {}
1520 void init(RGWRados
*store
, struct req_state
*s
, RGWHandler
*h
) override
{
1521 RGWOp::init(store
, s
, h
);
1522 policy
.set_ctx(s
->cct
);
1524 int verify_permission() override
;
1525 void pre_exec() override
;
1526 void execute() override
;
1528 virtual int get_params() = 0;
1529 void send_response() override
= 0;
1530 const string
name() override
{ return "init_multipart"; }
1531 RGWOpType
get_type() override
{ return RGW_OP_INIT_MULTIPART
; }
1532 uint32_t op_mask() override
{ return RGW_OP_TYPE_WRITE
; }
1533 virtual int prepare_encryption(map
<string
, bufferlist
>& attrs
) { return 0; }
1536 class RGWCompleteMultipart
: public RGWOp
{
1544 RGWCompleteMultipart() {
1548 ~RGWCompleteMultipart() override
{
1552 int verify_permission() override
;
1553 void pre_exec() override
;
1554 void execute() override
;
1556 virtual int get_params() = 0;
1557 void send_response() override
= 0;
1558 const string
name() override
{ return "complete_multipart"; }
1559 RGWOpType
get_type() override
{ return RGW_OP_COMPLETE_MULTIPART
; }
1560 uint32_t op_mask() override
{ return RGW_OP_TYPE_WRITE
; }
1563 class RGWAbortMultipart
: public RGWOp
{
1565 RGWAbortMultipart() {}
1567 int verify_permission() override
;
1568 void pre_exec() override
;
1569 void execute() override
;
1571 void send_response() override
= 0;
1572 const string
name() override
{ return "abort_multipart"; }
1573 RGWOpType
get_type() override
{ return RGW_OP_ABORT_MULTIPART
; }
1574 uint32_t op_mask() override
{ return RGW_OP_TYPE_DELETE
; }
1577 class RGWListMultipart
: public RGWOp
{
1580 map
<uint32_t, RGWUploadPartInfo
> parts
;
1583 RGWAccessControlPolicy policy
;
1587 RGWListMultipart() {
1593 void init(RGWRados
*store
, struct req_state
*s
, RGWHandler
*h
) override
{
1594 RGWOp::init(store
, s
, h
);
1595 policy
= RGWAccessControlPolicy(s
->cct
);
1597 int verify_permission() override
;
1598 void pre_exec() override
;
1599 void execute() override
;
1601 virtual int get_params() = 0;
1602 void send_response() override
= 0;
1603 const string
name() override
{ return "list_multipart"; }
1604 RGWOpType
get_type() override
{ return RGW_OP_LIST_MULTIPART
; }
1605 uint32_t op_mask() override
{ return RGW_OP_TYPE_READ
; }
1608 struct RGWMultipartUploadEntry
{
1609 rgw_bucket_dir_entry obj
;
1613 class RGWListBucketMultiparts
: public RGWOp
{
1617 RGWMultipartUploadEntry next_marker
;
1620 vector
<RGWMultipartUploadEntry
> uploads
;
1621 map
<string
, bool> common_prefixes
;
1626 RGWListBucketMultiparts() {
1628 is_truncated
= false;
1632 void init(RGWRados
*store
, struct req_state
*s
, RGWHandler
*h
) override
{
1633 RGWOp::init(store
, s
, h
);
1634 max_uploads
= default_max
;
1637 int verify_permission() override
;
1638 void pre_exec() override
;
1639 void execute() override
;
1641 virtual int get_params() = 0;
1642 void send_response() override
= 0;
1643 const string
name() override
{ return "list_bucket_multiparts"; }
1644 RGWOpType
get_type() override
{ return RGW_OP_LIST_BUCKET_MULTIPARTS
; }
1645 uint32_t op_mask() override
{ return RGW_OP_TYPE_READ
; }
1649 class RGWGetCrossDomainPolicy
: public RGWOp
{
1651 RGWGetCrossDomainPolicy() = default;
1652 ~RGWGetCrossDomainPolicy() override
= default;
1654 int verify_permission() override
{
1658 void execute() override
{
1662 const string
name() override
{
1663 return "get_crossdomain_policy";
1666 RGWOpType
get_type() override
{
1667 return RGW_OP_GET_CROSS_DOMAIN_POLICY
;
1670 uint32_t op_mask() override
{
1671 return RGW_OP_TYPE_READ
;
1676 class RGWGetHealthCheck
: public RGWOp
{
1678 RGWGetHealthCheck() = default;
1679 ~RGWGetHealthCheck() override
= default;
1681 int verify_permission() override
{
1685 void execute() override
;
1687 const string
name() override
{
1688 return "get_health_check";
1691 RGWOpType
get_type() override
{
1692 return RGW_OP_GET_HEALTH_CHECK
;
1695 uint32_t op_mask() override
{
1696 return RGW_OP_TYPE_READ
;
1701 class RGWDeleteMultiObj
: public RGWOp
{
1709 bool acl_allowed
= false;
1712 RGWDeleteMultiObj() {
1713 max_to_delete
= 1000;
1717 status_dumped
= false;
1719 int verify_permission() override
;
1720 void pre_exec() override
;
1721 void execute() override
;
1723 virtual int get_params() = 0;
1724 virtual void send_status() = 0;
1725 virtual void begin_response() = 0;
1726 virtual void send_partial_response(rgw_obj_key
& key
, bool delete_marker
,
1727 const string
& marker_version_id
, int ret
) = 0;
1728 virtual void end_response() = 0;
1729 const string
name() override
{ return "multi_object_delete"; }
1730 RGWOpType
get_type() override
{ return RGW_OP_DELETE_MULTI_OBJ
; }
1731 uint32_t op_mask() override
{ return RGW_OP_TYPE_DELETE
; }
1734 class RGWInfo
: public RGWOp
{
1736 RGWInfo() = default;
1737 ~RGWInfo() override
= default;
1739 int verify_permission() override
{ return 0; }
1740 const string
name() override
{ return "get info"; }
1741 RGWOpType
get_type() override
{ return RGW_OP_GET_INFO
; }
1742 uint32_t op_mask() override
{ return RGW_OP_TYPE_READ
; }
1745 extern int rgw_build_bucket_policies(RGWRados
* store
, struct req_state
* s
);
1746 extern int rgw_build_object_policies(RGWRados
*store
, struct req_state
*s
,
1747 bool prefetch_data
);
1748 extern rgw::IAM::Environment
rgw_build_iam_environment(RGWRados
* store
,
1749 struct req_state
* s
);
1751 static inline int put_data_and_throttle(RGWPutObjDataProcessor
*processor
,
1752 bufferlist
& data
, off_t ofs
,
1757 void *handle
= nullptr;
1760 uint64_t size
= data
.length();
1762 int ret
= processor
->handle_data(data
, ofs
, &handle
, &obj
, &again
);
1765 if (handle
!= nullptr)
1767 ret
= processor
->throttle_data(handle
, obj
, size
, need_to_wait
);
1773 need_to_wait
= false; /* the need to wait only applies to the first
1778 } /* put_data_and_throttle */
1784 static inline int get_system_versioning_params(req_state
*s
,
1785 uint64_t *olh_epoch
,
1788 if (!s
->system_request
) {
1793 string epoch_str
= s
->info
.args
.get(RGW_SYS_PARAM_PREFIX
"versioned-epoch");
1794 if (!epoch_str
.empty()) {
1796 *olh_epoch
= strict_strtol(epoch_str
.c_str(), 10, &err
);
1798 lsubdout(s
->cct
, rgw
, 0) << "failed to parse versioned-epoch param"
1806 *version_id
= s
->info
.args
.get(RGW_SYS_PARAM_PREFIX
"version-id");
1810 } /* get_system_versioning_params */
1812 static inline void format_xattr(std::string
&xattr
)
1814 /* If the extended attribute is not valid UTF-8, we encode it using
1815 * quoted-printable encoding.
1817 if ((check_utf8(xattr
.c_str(), xattr
.length()) != 0) ||
1818 (check_for_control_characters(xattr
.c_str(), xattr
.length()) != 0)) {
1819 static const char MIME_PREFIX_STR
[] = "=?UTF-8?Q?";
1820 static const int MIME_PREFIX_LEN
= sizeof(MIME_PREFIX_STR
) - 1;
1821 static const char MIME_SUFFIX_STR
[] = "?=";
1822 static const int MIME_SUFFIX_LEN
= sizeof(MIME_SUFFIX_STR
) - 1;
1823 int mlen
= mime_encode_as_qp(xattr
.c_str(), NULL
, 0);
1824 char *mime
= new char[MIME_PREFIX_LEN
+ mlen
+ MIME_SUFFIX_LEN
+ 1];
1825 strcpy(mime
, MIME_PREFIX_STR
);
1826 mime_encode_as_qp(xattr
.c_str(), mime
+ MIME_PREFIX_LEN
, mlen
);
1827 strcpy(mime
+ MIME_PREFIX_LEN
+ (mlen
- 1), MIME_SUFFIX_STR
);
1831 } /* format_xattr */
1834 * Get the HTTP request metadata out of the req_state as a
1835 * map(<attr_name, attr_contents>, where attr_name is RGW_ATTR_PREFIX.HTTP_NAME)
1836 * s: The request state
1837 * attrs: will be filled up with attrs mapped as <attr_name, attr_contents>
1840 static inline void rgw_get_request_metadata(CephContext
*cct
,
1841 struct req_info
& info
,
1842 map
<string
, bufferlist
>& attrs
,
1843 const bool allow_empty_attrs
= true)
1845 static const std::set
<std::string
> blacklisted_headers
= {
1846 "x-amz-server-side-encryption-customer-algorithm",
1847 "x-amz-server-side-encryption-customer-key",
1848 "x-amz-server-side-encryption-customer-key-md5"
1850 map
<string
, string
>::iterator iter
;
1851 for (iter
= info
.x_meta_map
.begin(); iter
!= info
.x_meta_map
.end(); ++iter
) {
1852 const string
&name(iter
->first
);
1853 string
&xattr(iter
->second
);
1854 if (blacklisted_headers
.count(name
) == 1) {
1855 lsubdout(cct
, rgw
, 10) << "skipping x>> " << name
<< dendl
;
1858 if (allow_empty_attrs
|| !xattr
.empty()) {
1859 lsubdout(cct
, rgw
, 10) << "x>> " << name
<< ":" << xattr
<< dendl
;
1860 format_xattr(xattr
);
1861 string
attr_name(RGW_ATTR_PREFIX
);
1862 attr_name
.append(name
);
1863 map
<string
, bufferlist
>::value_type
v(attr_name
, bufferlist());
1864 std::pair
< map
<string
, bufferlist
>::iterator
, bool >
1865 rval(attrs
.insert(v
));
1866 bufferlist
& bl(rval
.first
->second
);
1867 bl
.append(xattr
.c_str(), xattr
.size() + 1);
1870 } /* rgw_get_request_metadata */
1872 static inline void encode_delete_at_attr(boost::optional
<ceph::real_time
> delete_at
,
1873 map
<string
, bufferlist
>& attrs
)
1875 if (delete_at
== boost::none
) {
1880 ::encode(*delete_at
, delatbl
);
1881 attrs
[RGW_ATTR_DELETE_AT
] = delatbl
;
1882 } /* encode_delete_at_attr */
1884 static inline int encode_dlo_manifest_attr(const char * const dlo_manifest
,
1885 map
<string
, bufferlist
>& attrs
)
1887 string dm
= dlo_manifest
;
1889 if (dm
.find('/') == string::npos
) {
1893 bufferlist manifest_bl
;
1894 manifest_bl
.append(dlo_manifest
, strlen(dlo_manifest
) + 1);
1895 attrs
[RGW_ATTR_USER_MANIFEST
] = manifest_bl
;
1898 } /* encode_dlo_manifest_attr */
1900 static inline void complete_etag(MD5
& hash
, string
*etag
)
1902 char etag_buf
[CEPH_CRYPTO_MD5_DIGESTSIZE
];
1903 char etag_buf_str
[CEPH_CRYPTO_MD5_DIGESTSIZE
* 2 + 16];
1905 hash
.Final((byte
*)etag_buf
);
1906 buf_to_hex((const unsigned char *)etag_buf
, CEPH_CRYPTO_MD5_DIGESTSIZE
,
1909 *etag
= etag_buf_str
;
1910 } /* complete_etag */
1912 class RGWSetAttrs
: public RGWOp
{
1914 map
<string
, buffer::list
> attrs
;
1918 ~RGWSetAttrs() override
{}
1920 void emplace_attr(std::string
&& key
, buffer::list
&& bl
) {
1921 attrs
.emplace(std::move(key
), std::move(bl
));
1924 int verify_permission() override
;
1925 void pre_exec() override
;
1926 void execute() override
;
1928 virtual int get_params() = 0;
1929 void send_response() override
= 0;
1930 const string
name() override
{ return "set_attrs"; }
1931 RGWOpType
get_type() override
{ return RGW_OP_SET_ATTRS
; }
1932 uint32_t op_mask() override
{ return RGW_OP_TYPE_WRITE
; }
1935 class RGWGetObjLayout
: public RGWOp
{
1937 RGWObjManifest
*manifest
{nullptr};
1938 rgw_raw_obj head_obj
;
1944 int check_caps(RGWUserCaps
& caps
) {
1945 return caps
.check_cap("admin", RGW_CAP_READ
);
1947 int verify_permission() {
1948 return check_caps(s
->user
->caps
);
1953 virtual void send_response() = 0;
1954 virtual const string
name() { return "get_obj_layout"; }
1955 virtual RGWOpType
get_type() { return RGW_OP_GET_OBJ_LAYOUT
; }
1956 virtual uint32_t op_mask() { return RGW_OP_TYPE_READ
; }
1959 class RGWPutBucketPolicy
: public RGWOp
{
1961 char *data
= nullptr;
1963 RGWPutBucketPolicy() = default;
1964 ~RGWPutBucketPolicy() {
1966 free(static_cast<void*>(data
));
1969 void send_response() override
;
1970 int verify_permission() override
;
1971 uint32_t op_mask() override
{
1972 return RGW_OP_TYPE_WRITE
;
1974 void execute() override
;
1976 const std::string
name() override
{
1977 return "put_bucket_policy";
1979 RGWOpType
get_type() override
{
1980 return RGW_OP_PUT_BUCKET_POLICY
;
1984 class RGWGetBucketPolicy
: public RGWOp
{
1985 buffer::list policy
;
1987 RGWGetBucketPolicy() = default;
1988 void send_response() override
;
1989 int verify_permission() override
;
1990 uint32_t op_mask() override
{
1991 return RGW_OP_TYPE_READ
;
1993 void execute() override
;
1994 const std::string
name() override
{
1995 return "get_bucket_policy";
1997 RGWOpType
get_type() override
{
1998 return RGW_OP_GET_BUCKET_POLICY
;
2002 class RGWDeleteBucketPolicy
: public RGWOp
{
2004 RGWDeleteBucketPolicy() = default;
2005 void send_response() override
;
2006 int verify_permission() override
;
2007 uint32_t op_mask() override
{
2008 return RGW_OP_TYPE_WRITE
;
2010 void execute() override
;
2012 const std::string
name() override
{
2013 return "delete_bucket_policy";
2015 RGWOpType
get_type() override
{
2016 return RGW_OP_DELETE_BUCKET_POLICY
;
2021 class RGWConfigBucketMetaSearch
: public RGWOp
{
2023 std::map
<std::string
, uint32_t> mdsearch_config
;
2025 RGWConfigBucketMetaSearch() {}
2027 int verify_permission();
2031 virtual int get_params() = 0;
2032 virtual void send_response() = 0;
2033 virtual const string
name() { return "config_bucket_meta_search"; }
2034 virtual RGWOpType
get_type() { return RGW_OP_CONFIG_BUCKET_META_SEARCH
; }
2035 virtual uint32_t op_mask() { return RGW_OP_TYPE_WRITE
; }
2038 class RGWGetBucketMetaSearch
: public RGWOp
{
2040 RGWGetBucketMetaSearch() {}
2042 int verify_permission();
2046 virtual void send_response() = 0;
2047 virtual const string
name() { return "get_bucket_meta_search"; }
2048 virtual RGWOpType
get_type() { return RGW_OP_GET_BUCKET_META_SEARCH
; }
2049 virtual uint32_t op_mask() { return RGW_OP_TYPE_READ
; }
2052 class RGWDelBucketMetaSearch
: public RGWOp
{
2054 RGWDelBucketMetaSearch() {}
2056 int verify_permission();
2060 virtual void send_response() = 0;
2061 virtual const string
name() { return "delete_bucket_meta_search"; }
2062 virtual RGWOpType
delete_type() { return RGW_OP_DEL_BUCKET_META_SEARCH
; }
2063 virtual uint32_t op_mask() { return RGW_OP_TYPE_WRITE
; }
2066 #endif /* CEPH_RGW_OP_H */