]> git.proxmox.com Git - ceph.git/blame - ceph/src/rgw/rgw_op.h
import quincy beta 17.1.0
[ceph.git] / ceph / src / rgw / rgw_op.h
CommitLineData
31f18b77 1// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
9f95a23c 2// vim: ts=8 sw=2 smarttab ft=cpp
11fdf7f2 3
7c673cae
FG
4/**
5 * All operations via the rados gateway are carried out by
6 * small classes known as RGWOps. This class contains a req_state
7 * and each possible command is a subclass of this with a defined
8 * execute() method that does whatever the subclass name implies.
9 * These subclasses must be further subclassed (by interface type)
10 * to provide additional virtual methods such as send_response or get_params.
11 */
11fdf7f2 12
7c673cae
FG
13#ifndef CEPH_RGW_OP_H
14#define CEPH_RGW_OP_H
15
16#include <limits.h>
17
18#include <array>
19#include <memory>
20#include <string>
21#include <set>
22#include <map>
23#include <vector>
24
25#include <boost/optional.hpp>
26#include <boost/utility/in_place_factory.hpp>
31f18b77 27#include <boost/function.hpp>
f67539c2 28#include <boost/container/flat_map.hpp>
7c673cae
FG
29
30#include "common/armor.h"
31#include "common/mime.h"
32#include "common/utf8.h"
33#include "common/ceph_json.h"
7c673cae
FG
34#include "common/ceph_time.h"
35
36#include "rgw_common.h"
11fdf7f2 37#include "rgw_dmclock.h"
9f95a23c 38#include "rgw_sal.h"
7c673cae
FG
39#include "rgw_user.h"
40#include "rgw_bucket.h"
41#include "rgw_acl.h"
42#include "rgw_cors.h"
43#include "rgw_quota.h"
11fdf7f2 44#include "rgw_putobj.h"
9f95a23c 45#include "rgw_sal.h"
20effc67 46#include "rgw_compression_types.h"
7c673cae
FG
47
48#include "rgw_lc.h"
49#include "rgw_torrent.h"
224ce89b 50#include "rgw_tag.h"
eafe8130 51#include "rgw_object_lock.h"
3efd9988 52#include "cls/rgw/cls_rgw_client.h"
9f95a23c 53#include "rgw_public_access.h"
20effc67
TL
54#include "rgw_bucket_encryption.h"
55#include "rgw_tracer.h"
7c673cae 56
11fdf7f2 57#include "services/svc_sys_obj.h"
9f95a23c 58#include "services/svc_tier_rados.h"
11fdf7f2
TL
59
60#include "include/ceph_assert.h"
7c673cae 61
7c673cae
FG
62using ceph::crypto::SHA1;
63
64struct req_state;
65class RGWOp;
9f95a23c 66class RGWRados;
20effc67 67class RGWMultiCompleteUpload;
7c673cae
FG
68
69
70namespace rgw {
71namespace auth {
72namespace registry {
73
74class StrategyRegistry;
75
76}
77}
78}
79
b3b6e05e
TL
80int rgw_op_get_bucket_policy_from_attr(const DoutPrefixProvider *dpp,
81 CephContext *cct,
20effc67 82 rgw::sal::Store* store,
11fdf7f2 83 RGWBucketInfo& bucket_info,
20effc67 84 std::map<std::string, bufferlist>& bucket_attrs,
f67539c2
TL
85 RGWAccessControlPolicy *policy,
86 optional_yield y);
7c673cae
FG
87
88class RGWHandler {
89protected:
20effc67 90 rgw::sal::Store* store{nullptr};
9f95a23c 91 struct req_state *s{nullptr};
7c673cae 92
b3b6e05e 93 int do_init_permissions(const DoutPrefixProvider *dpp, optional_yield y);
f67539c2 94 int do_read_permissions(RGWOp* op, bool only_bucket, optional_yield y);
7c673cae
FG
95
96public:
9f95a23c 97 RGWHandler() {}
7c673cae
FG
98 virtual ~RGWHandler();
99
20effc67 100 virtual int init(rgw::sal::Store* store,
7c673cae
FG
101 struct req_state* _s,
102 rgw::io::BasicClient* cio);
103
f67539c2 104 virtual int init_permissions(RGWOp*, optional_yield y) {
7c673cae
FG
105 return 0;
106 }
107
f67539c2 108 virtual int retarget(RGWOp* op, RGWOp** new_op, optional_yield) {
7c673cae
FG
109 *new_op = op;
110 return 0;
111 }
112
f67539c2
TL
113 virtual int read_permissions(RGWOp* op, optional_yield y) = 0;
114 virtual int authorize(const DoutPrefixProvider* dpp, optional_yield y) = 0;
115 virtual int postauth_init(optional_yield y) = 0;
116 virtual int error_handler(int err_no, std::string* error_content, optional_yield y);
20effc67 117 virtual void dump(const std::string& code, const std::string& message) const {}
11fdf7f2
TL
118
119 virtual bool supports_quota() {
120 return true;
121 }
7c673cae
FG
122};
123
124
31f18b77
FG
125
126void rgw_bucket_object_pre_exec(struct req_state *s);
127
11fdf7f2
TL
128namespace dmc = rgw::dmclock;
129
20effc67
TL
130std::tuple<int, bufferlist > rgw_rest_read_all_input(struct req_state *s,
131 const uint64_t max_len,
132 const bool allow_chunked=true);
133
134template <class T>
135int rgw_rest_get_json_input(CephContext *cct, req_state *s, T& out,
136 uint64_t max_len, bool *empty)
137{
138 if (empty)
139 *empty = false;
140
141 int rv = 0;
142 bufferlist data;
143 std::tie(rv, data) = rgw_rest_read_all_input(s, max_len);
144 if (rv < 0) {
145 return rv;
146 }
147
148 if (!data.length()) {
149 if (empty) {
150 *empty = true;
151 }
152
153 return -EINVAL;
154 }
155
156 JSONParser parser;
157
158 if (!parser.parse(data.c_str(), data.length())) {
159 return -EINVAL;
160 }
161
162 try {
163 decode_json_obj(out, &parser);
164 } catch (JSONDecoder::err& e) {
165 return -EINVAL;
166 }
167
168 return 0;
169}
170
7c673cae
FG
171/**
172 * Provide the base class for all ops.
173 */
11fdf7f2 174class RGWOp : public DoutPrefixProvider {
7c673cae
FG
175protected:
176 struct req_state *s;
177 RGWHandler *dialect_handler;
20effc67 178 rgw::sal::Store* store;
7c673cae
FG
179 RGWCORSConfiguration bucket_cors;
180 bool cors_exist;
181 RGWQuotaInfo bucket_quota;
182 RGWQuotaInfo user_quota;
183 int op_ret;
7c673cae
FG
184 int do_aws4_auth_completion();
185
186 virtual int init_quota();
b32b8144 187
20effc67
TL
188 std::tuple<int, bufferlist> read_all_input(struct req_state *s,
189 const uint64_t max_len,
190 const bool allow_chunked=true) {
191
192 int rv = 0;
193 bufferlist data;
194 std::tie(rv, data) = rgw_rest_read_all_input(s, max_len);
195 if (rv >= 0) {
196 do_aws4_auth_completion();
197 }
198
199 return std::make_tuple(rv, std::move(data));
200 }
201
202 template <class T>
203 int get_json_input(CephContext *cct, req_state *s, T& out,
204 uint64_t max_len, bool *empty) {
205 int r = rgw_rest_get_json_input(cct, s, out, max_len, empty);
206 if (r >= 0) {
207 do_aws4_auth_completion();
208 }
209 return r;
210 }
211
7c673cae
FG
212public:
213 RGWOp()
214 : s(nullptr),
215 dialect_handler(nullptr),
216 store(nullptr),
217 cors_exist(false),
218 op_ret(0) {
219 }
220
20effc67 221 virtual ~RGWOp() override;
7c673cae
FG
222
223 int get_ret() const { return op_ret; }
224
f67539c2 225 virtual int init_processing(optional_yield y) {
11fdf7f2
TL
226 if (dialect_handler->supports_quota()) {
227 op_ret = init_quota();
228 if (op_ret < 0)
229 return op_ret;
230 }
7c673cae
FG
231
232 return 0;
233 }
234
20effc67 235 virtual void init(rgw::sal::Store* store, struct req_state *s, RGWHandler *dialect_handler) {
7c673cae
FG
236 this->store = store;
237 this->s = s;
238 this->dialect_handler = dialect_handler;
239 }
240 int read_bucket_cors();
20effc67 241 bool generate_cors_headers(std::string& origin, std::string& method, std::string& headers, std::string& exp_headers, unsigned *max_age);
7c673cae
FG
242
243 virtual int verify_params() { return 0; }
244 virtual bool prefetch_data() { return false; }
245
246 /* Authenticate requester -- verify its identity.
247 *
248 * NOTE: typically the procedure is common across all operations of the same
249 * dialect (S3, Swift API). However, there are significant exceptions in
250 * both APIs: browser uploads, /info and OPTIONS handlers. All of them use
251 * different, specific authentication schema driving the need for per-op
252 * authentication. The alternative is to duplicate parts of the method-
253 * dispatch logic in RGWHandler::authorize() and pollute it with a lot
254 * of special cases. */
f67539c2 255 virtual int verify_requester(const rgw::auth::StrategyRegistry& auth_registry, optional_yield y) {
7c673cae 256 /* TODO(rzarzynski): rename RGWHandler::authorize to generic_authenticate. */
f67539c2 257 return dialect_handler->authorize(this, y);
7c673cae 258 }
f67539c2 259 virtual int verify_permission(optional_yield y) = 0;
7c673cae
FG
260 virtual int verify_op_mask();
261 virtual void pre_exec() {}
f67539c2 262 virtual void execute(optional_yield y) = 0;
7c673cae
FG
263 virtual void send_response() {}
264 virtual void complete() {
265 send_response();
266 }
11fdf7f2 267 virtual const char* name() const = 0;
7c673cae
FG
268 virtual RGWOpType get_type() { return RGW_OP_UNKNOWN; }
269
270 virtual uint32_t op_mask() { return 0; }
271
20effc67 272 virtual int error_handler(int err_no, std::string *error_content, optional_yield y);
11fdf7f2
TL
273
274 // implements DoutPrefixProvider
275 std::ostream& gen_prefix(std::ostream& out) const override;
276 CephContext* get_cct() const override { return s->cct; }
277 unsigned get_subsys() const override { return ceph_subsys_rgw; }
278
279 virtual dmc::client_id dmclock_client() { return dmc::client_id::metadata; }
280 virtual dmc::Cost dmclock_cost() { return 1; }
281};
282
283class RGWDefaultResponseOp : public RGWOp {
284public:
285 void send_response() override;
286};
287
288class RGWGetObj_Filter : public RGWGetDataCB
289{
290protected:
291 RGWGetObj_Filter *next{nullptr};
292public:
293 RGWGetObj_Filter() {}
294 explicit RGWGetObj_Filter(RGWGetObj_Filter *next): next(next) {}
295 ~RGWGetObj_Filter() override {}
296 /**
297 * Passes data through filter.
298 * Filter can modify content of bl.
299 * When bl_len == 0 , it means 'flush
300 */
301 int handle_data(bufferlist& bl, off_t bl_ofs, off_t bl_len) override {
302 if (next) {
303 return next->handle_data(bl, bl_ofs, bl_len);
304 }
305 return 0;
306 }
307 /**
308 * Flushes any cached data. Used by RGWGetObjFilter.
309 * Return logic same as handle_data.
310 */
311 virtual int flush() {
312 if (next) {
313 return next->flush();
314 }
315 return 0;
316 }
317 /**
318 * Allows filter to extend range required for successful filtering
319 */
320 virtual int fixup_range(off_t& ofs, off_t& end) {
321 if (next) {
322 return next->fixup_range(ofs, end);
323 }
324 return 0;
325 }
7c673cae
FG
326};
327
328class RGWGetObj : public RGWOp {
329protected:
330 seed torrent; // get torrent
331 const char *range_str;
332 const char *if_mod;
333 const char *if_unmod;
334 const char *if_match;
335 const char *if_nomatch;
336 uint32_t mod_zone_id;
337 uint64_t mod_pg_ver;
338 off_t ofs;
339 uint64_t total_len;
340 off_t start;
341 off_t end;
342 ceph::real_time mod_time;
343 ceph::real_time lastmod;
344 ceph::real_time unmod_time;
345 ceph::real_time *mod_ptr;
346 ceph::real_time *unmod_ptr;
20effc67 347 rgw::sal::Attrs attrs;
7c673cae
FG
348 bool get_data;
349 bool partial_content;
28e407b8 350 bool ignore_invalid_range;
7c673cae
FG
351 bool range_parsed;
352 bool skip_manifest;
181888fb 353 bool skip_decrypt{false};
7c673cae
FG
354 utime_t gc_invalidate_time;
355 bool is_slo;
20effc67 356 std::string lo_etag;
7c673cae 357 bool rgwx_stat; /* extended rgw stat operation */
20effc67 358 std::string version_id;
7c673cae
FG
359
360 // compression attrs
361 RGWCompressionInfo cs_info;
362 off_t first_block, last_block;
363 off_t q_ofs, q_len;
364 bool first_data;
365 uint64_t cur_ofs;
366 bufferlist waiting;
31f18b77 367 uint64_t action = 0;
7c673cae 368
eafe8130
TL
369 bool get_retention;
370 bool get_legal_hold;
371
7c673cae
FG
372 int init_common();
373public:
374 RGWGetObj() {
375 range_str = NULL;
376 if_mod = NULL;
377 if_unmod = NULL;
378 if_match = NULL;
379 if_nomatch = NULL;
380 mod_zone_id = 0;
381 mod_pg_ver = 0;
382 start = 0;
383 ofs = 0;
384 total_len = 0;
385 end = -1;
386 mod_ptr = NULL;
387 unmod_ptr = NULL;
388 get_data = false;
389 partial_content = false;
390 range_parsed = false;
391 skip_manifest = false;
392 is_slo = false;
393 first_block = 0;
394 last_block = 0;
395 q_ofs = 0;
396 q_len = 0;
397 first_data = true;
398 cur_ofs = 0;
eafe8130
TL
399 get_retention = false;
400 get_legal_hold = false;
7c673cae
FG
401 }
402
403 bool prefetch_data() override;
404
405 void set_get_data(bool get_data) {
406 this->get_data = get_data;
407 }
28e407b8 408
f67539c2 409 int verify_permission(optional_yield y) override;
7c673cae 410 void pre_exec() override;
f67539c2 411 void execute(optional_yield y) override;
28e407b8 412 int parse_range();
31f18b77 413 int read_user_manifest_part(
20effc67 414 rgw::sal::Bucket* bucket,
31f18b77
FG
415 const rgw_bucket_dir_entry& ent,
416 RGWAccessControlPolicy * const bucket_acl,
417 const boost::optional<rgw::IAM::Policy>& bucket_policy,
418 const off_t start_ofs,
11fdf7f2
TL
419 const off_t end_ofs,
420 bool swift_slo);
f67539c2
TL
421 int handle_user_manifest(const char *prefix, optional_yield y);
422 int handle_slo_manifest(bufferlist& bl, optional_yield y);
7c673cae
FG
423
424 int get_data_cb(bufferlist& bl, off_t ofs, off_t len);
425
f67539c2
TL
426 virtual int get_params(optional_yield y) = 0;
427 virtual int send_response_data_error(optional_yield y) = 0;
7c673cae
FG
428 virtual int send_response_data(bufferlist& bl, off_t ofs, off_t len) = 0;
429
11fdf7f2 430 const char* name() const override { return "get_obj"; }
7c673cae
FG
431 RGWOpType get_type() override { return RGW_OP_GET_OBJ; }
432 uint32_t op_mask() override { return RGW_OP_TYPE_READ; }
433 virtual bool need_object_expiration() { return false; }
434 /**
435 * calculates filter used to decrypt RGW objects data
436 */
11fdf7f2 437 virtual int get_decrypt_filter(std::unique_ptr<RGWGetObj_Filter>* filter, RGWGetObj_Filter* cb, bufferlist* manifest_bl) {
7c673cae
FG
438 *filter = nullptr;
439 return 0;
440 }
11fdf7f2 441 dmc::client_id dmclock_client() override { return dmc::client_id::data; }
7c673cae
FG
442};
443
11fdf7f2 444class RGWGetObj_CB : public RGWGetObj_Filter
7c673cae
FG
445{
446 RGWGetObj *op;
447public:
448 explicit RGWGetObj_CB(RGWGetObj *_op) : op(_op) {}
449 ~RGWGetObj_CB() override {}
450
451 int handle_data(bufferlist& bl, off_t bl_ofs, off_t bl_len) override {
452 return op->get_data_cb(bl, bl_ofs, bl_len);
453 }
454};
455
224ce89b
WB
456class RGWGetObjTags : public RGWOp {
457 protected:
458 bufferlist tags_bl;
459 bool has_tags{false};
460 public:
f67539c2
TL
461 int verify_permission(optional_yield y) override;
462 void execute(optional_yield y) override;
11fdf7f2 463 void pre_exec() override;
224ce89b
WB
464
465 virtual void send_response_data(bufferlist& bl) = 0;
11fdf7f2
TL
466 const char* name() const override { return "get_obj_tags"; }
467 virtual uint32_t op_mask() override { return RGW_OP_TYPE_READ; }
468 RGWOpType get_type() override { return RGW_OP_GET_OBJ_TAGGING; }
224ce89b
WB
469
470};
471
472class RGWPutObjTags : public RGWOp {
473 protected:
474 bufferlist tags_bl;
475 public:
f67539c2
TL
476 int verify_permission(optional_yield y) override;
477 void execute(optional_yield y) override;
224ce89b 478
11fdf7f2 479 virtual void send_response() override = 0;
f67539c2 480 virtual int get_params(optional_yield y) = 0;
11fdf7f2
TL
481 const char* name() const override { return "put_obj_tags"; }
482 virtual uint32_t op_mask() override { return RGW_OP_TYPE_WRITE; }
483 RGWOpType get_type() override { return RGW_OP_PUT_OBJ_TAGGING; }
224ce89b
WB
484
485};
486
487class RGWDeleteObjTags: public RGWOp {
488 public:
11fdf7f2 489 void pre_exec() override;
f67539c2
TL
490 int verify_permission(optional_yield y) override;
491 void execute(optional_yield y) override;
224ce89b 492
11fdf7f2
TL
493 const char* name() const override { return "delete_obj_tags"; }
494 virtual uint32_t op_mask() override { return RGW_OP_TYPE_DELETE; }
495 RGWOpType get_type() override { return RGW_OP_DELETE_OBJ_TAGGING;}
224ce89b
WB
496};
497
9f95a23c
TL
498class RGWGetBucketTags : public RGWOp {
499protected:
500 bufferlist tags_bl;
501 bool has_tags{false};
502public:
f67539c2
TL
503 int verify_permission(optional_yield y) override;
504 void execute(optional_yield y) override;
9f95a23c
TL
505 void pre_exec() override;
506
507 virtual void send_response_data(bufferlist& bl) = 0;
508 const char* name() const override { return "get_bucket_tags"; }
509 virtual uint32_t op_mask() override { return RGW_OP_TYPE_READ; }
510 RGWOpType get_type() override { return RGW_OP_GET_BUCKET_TAGGING; }
511};
512
513class RGWPutBucketTags : public RGWOp {
514protected:
515 bufferlist tags_bl;
516 bufferlist in_data;
517public:
f67539c2
TL
518 int verify_permission(optional_yield y) override;
519 void execute(optional_yield y) override;
9f95a23c
TL
520
521 virtual void send_response() override = 0;
b3b6e05e 522 virtual int get_params(const DoutPrefixProvider *dpp, optional_yield y) = 0;
9f95a23c
TL
523 const char* name() const override { return "put_bucket_tags"; }
524 virtual uint32_t op_mask() override { return RGW_OP_TYPE_WRITE; }
525 RGWOpType get_type() override { return RGW_OP_PUT_BUCKET_TAGGING; }
526};
527
528class RGWDeleteBucketTags : public RGWOp {
529public:
530 void pre_exec() override;
f67539c2
TL
531 int verify_permission(optional_yield y) override;
532 void execute(optional_yield y) override;
9f95a23c
TL
533
534 const char* name() const override { return "delete_bucket_tags"; }
535 virtual uint32_t op_mask() override { return RGW_OP_TYPE_DELETE; }
536 RGWOpType get_type() override { return RGW_OP_DELETE_BUCKET_TAGGING;}
537};
538
539struct rgw_sync_policy_group;
540
541class RGWGetBucketReplication : public RGWOp {
542public:
f67539c2
TL
543 int verify_permission(optional_yield y) override;
544 void execute(optional_yield y) override;
9f95a23c
TL
545 void pre_exec() override;
546
547 virtual void send_response_data() = 0;
548 const char* name() const override { return "get_bucket_replication"; }
549 virtual uint32_t op_mask() override { return RGW_OP_TYPE_READ; }
550 RGWOpType get_type() override { return RGW_OP_GET_BUCKET_REPLICATION; }
551};
552
553class RGWPutBucketReplication : public RGWOp {
554protected:
555 bufferlist in_data;
556 std::vector<rgw_sync_policy_group> sync_policy_groups;
557public:
f67539c2
TL
558 int verify_permission(optional_yield y) override;
559 void execute(optional_yield y) override;
9f95a23c
TL
560
561 virtual void send_response() override = 0;
f67539c2 562 virtual int get_params(optional_yield y) = 0;
9f95a23c
TL
563 const char* name() const override { return "put_bucket_replication"; }
564 virtual uint32_t op_mask() override { return RGW_OP_TYPE_WRITE; }
565 RGWOpType get_type() override { return RGW_OP_PUT_BUCKET_REPLICATION; }
566};
567
568class RGWDeleteBucketReplication : public RGWOp {
569protected:
570 virtual void update_sync_policy(rgw_sync_policy_info *policy) = 0;
571public:
572 void pre_exec() override;
f67539c2
TL
573 int verify_permission(optional_yield y) override;
574 void execute(optional_yield y) override;
9f95a23c
TL
575
576 const char* name() const override { return "delete_bucket_replication"; }
577 virtual uint32_t op_mask() override { return RGW_OP_TYPE_DELETE; }
578 RGWOpType get_type() override { return RGW_OP_DELETE_BUCKET_REPLICATION;}
579};
580
7c673cae
FG
581class RGWBulkDelete : public RGWOp {
582public:
583 struct acct_path_t {
584 std::string bucket_name;
585 rgw_obj_key obj_key;
586 };
587
588 struct fail_desc_t {
589 int err;
590 acct_path_t path;
591 };
592
593 class Deleter {
594 protected:
11fdf7f2 595 const DoutPrefixProvider * dpp;
7c673cae
FG
596 unsigned int num_deleted;
597 unsigned int num_unfound;
598 std::list<fail_desc_t> failures;
599
20effc67 600 rgw::sal::Store* const store;
7c673cae
FG
601 req_state * const s;
602
603 public:
20effc67 604 Deleter(const DoutPrefixProvider* dpp, rgw::sal::Store* const str, req_state * const s)
11fdf7f2
TL
605 : dpp(dpp),
606 num_deleted(0),
7c673cae
FG
607 num_unfound(0),
608 store(str),
609 s(s) {
610 }
611
612 unsigned int get_num_deleted() const {
613 return num_deleted;
614 }
615
616 unsigned int get_num_unfound() const {
617 return num_unfound;
618 }
619
620 const std::list<fail_desc_t> get_failures() const {
621 return failures;
622 }
623
624 bool verify_permission(RGWBucketInfo& binfo,
20effc67 625 std::map<std::string, bufferlist>& battrs,
f67539c2
TL
626 ACLOwner& bucket_owner /* out */,
627 optional_yield y);
628 bool delete_single(const acct_path_t& path, optional_yield y);
629 bool delete_chunk(const std::list<acct_path_t>& paths, optional_yield y);
7c673cae
FG
630 };
631 /* End of Deleter subclass */
632
633 static const size_t MAX_CHUNK_ENTRIES = 1024;
634
635protected:
636 std::unique_ptr<Deleter> deleter;
637
638public:
639 RGWBulkDelete()
640 : deleter(nullptr) {
641 }
642
f67539c2 643 int verify_permission(optional_yield y) override;
7c673cae 644 void pre_exec() override;
f67539c2 645 void execute(optional_yield y) override;
7c673cae
FG
646
647 virtual int get_data(std::list<acct_path_t>& items,
648 bool * is_truncated) = 0;
649 void send_response() override = 0;
650
11fdf7f2 651 const char* name() const override { return "bulk_delete"; }
7c673cae
FG
652 RGWOpType get_type() override { return RGW_OP_BULK_DELETE; }
653 uint32_t op_mask() override { return RGW_OP_TYPE_DELETE; }
11fdf7f2 654 dmc::client_id dmclock_client() override { return dmc::client_id::data; }
7c673cae
FG
655};
656
20effc67 657inline std::ostream& operator<<(std::ostream& out, const RGWBulkDelete::acct_path_t &o) {
7c673cae
FG
658 return out << o.bucket_name << "/" << o.obj_key;
659}
660
661
662class RGWBulkUploadOp : public RGWOp {
7c673cae
FG
663protected:
664 class fail_desc_t {
665 public:
666 fail_desc_t(const int err, std::string path)
667 : err(err),
668 path(std::move(path)) {
669 }
670
671 const int err;
672 const std::string path;
673 };
674
675 static constexpr std::array<int, 2> terminal_errors = {
676 { -EACCES, -EPERM }
677 };
678
679 /* FIXME: boost::container::small_vector<fail_desc_t, 4> failures; */
680 std::vector<fail_desc_t> failures;
681 size_t num_created;
682
683 class StreamGetter;
684 class DecoratedStreamGetter;
685 class AlignedStreamGetter;
686
687 virtual std::unique_ptr<StreamGetter> create_stream() = 0;
11fdf7f2 688 virtual void send_response() override = 0;
7c673cae
FG
689
690 boost::optional<std::pair<std::string, rgw_obj_key>>
f67539c2 691 parse_path(const std::string_view& path);
7c673cae
FG
692
693 std::pair<std::string, std::string>
694 handle_upload_path(struct req_state *s);
695
696 bool handle_file_verify_permission(RGWBucketInfo& binfo,
31f18b77
FG
697 const rgw_obj& obj,
698 std::map<std::string, ceph::bufferlist>& battrs,
f67539c2
TL
699 ACLOwner& bucket_owner /* out */,
700 optional_yield y);
701 int handle_file(std::string_view path,
7c673cae 702 size_t size,
f67539c2
TL
703 AlignedStreamGetter& body,
704 optional_yield y);
7c673cae 705
f67539c2
TL
706 int handle_dir_verify_permission(optional_yield y);
707 int handle_dir(std::string_view path, optional_yield y);
7c673cae
FG
708
709public:
710 RGWBulkUploadOp()
711 : num_created(0) {
712 }
713
20effc67 714 void init(rgw::sal::Store* const store,
7c673cae 715 struct req_state* const s,
11fdf7f2 716 RGWHandler* const h) override;
7c673cae 717
f67539c2 718 int verify_permission(optional_yield y) override;
7c673cae 719 void pre_exec() override;
f67539c2 720 void execute(optional_yield y) override;
7c673cae 721
11fdf7f2 722 const char* name() const override { return "bulk_upload"; }
7c673cae
FG
723
724 RGWOpType get_type() override {
725 return RGW_OP_BULK_UPLOAD;
726 }
727
728 uint32_t op_mask() override {
729 return RGW_OP_TYPE_WRITE;
730 }
11fdf7f2 731 dmc::client_id dmclock_client() override { return dmc::client_id::data; }
7c673cae
FG
732}; /* RGWBulkUploadOp */
733
734
735class RGWBulkUploadOp::StreamGetter {
736public:
737 StreamGetter() = default;
738 virtual ~StreamGetter() = default;
739
740 virtual ssize_t get_at_most(size_t want, ceph::bufferlist& dst) = 0;
741 virtual ssize_t get_exactly(size_t want, ceph::bufferlist& dst) = 0;
742}; /* End of nested subclass StreamGetter */
743
744
745class RGWBulkUploadOp::DecoratedStreamGetter : public StreamGetter {
746 StreamGetter& decoratee;
747
748protected:
749 StreamGetter& get_decoratee() {
750 return decoratee;
751 }
752
753public:
11fdf7f2 754 explicit DecoratedStreamGetter(StreamGetter& decoratee)
7c673cae
FG
755 : decoratee(decoratee) {
756 }
757 virtual ~DecoratedStreamGetter() = default;
758
759 ssize_t get_at_most(const size_t want, ceph::bufferlist& dst) override {
760 return get_decoratee().get_at_most(want, dst);
761 }
762
763 ssize_t get_exactly(const size_t want, ceph::bufferlist& dst) override {
764 return get_decoratee().get_exactly(want, dst);
765 }
766}; /* RGWBulkUploadOp::DecoratedStreamGetter */
767
768
769class RGWBulkUploadOp::AlignedStreamGetter
770 : public RGWBulkUploadOp::DecoratedStreamGetter {
771 size_t position;
772 size_t length;
773 size_t alignment;
774
775public:
776 template <typename U>
777 AlignedStreamGetter(const size_t position,
778 const size_t length,
779 const size_t alignment,
780 U&& decoratee)
781 : DecoratedStreamGetter(std::forward<U>(decoratee)),
782 position(position),
783 length(length),
784 alignment(alignment) {
785 }
786 virtual ~AlignedStreamGetter();
787 ssize_t get_at_most(size_t want, ceph::bufferlist& dst) override;
788 ssize_t get_exactly(size_t want, ceph::bufferlist& dst) override;
789}; /* RGWBulkUploadOp::AlignedStreamGetter */
790
791
3efd9988
FG
792struct RGWUsageStats {
793 uint64_t bytes_used = 0;
794 uint64_t bytes_used_rounded = 0;
795 uint64_t buckets_count = 0;
796 uint64_t objects_count = 0;
797};
798
7c673cae
FG
799#define RGW_LIST_BUCKETS_LIMIT_MAX 10000
800
801class RGWListBuckets : public RGWOp {
802protected:
803 bool sent_data;
3efd9988
FG
804 std::string marker;
805 std::string end_marker;
7c673cae
FG
806 int64_t limit;
807 uint64_t limit_max;
7c673cae
FG
808 bool is_truncated;
809
3efd9988
FG
810 RGWUsageStats global_stats;
811 std::map<std::string, RGWUsageStats> policies_stats;
812
7c673cae
FG
813 virtual uint64_t get_default_max() const {
814 return 1000;
815 }
816
817public:
3efd9988
FG
818 RGWListBuckets()
819 : sent_data(false),
820 limit(RGW_LIST_BUCKETS_LIMIT_MAX),
821 limit_max(RGW_LIST_BUCKETS_LIMIT_MAX),
822 is_truncated(false) {
7c673cae
FG
823 }
824
f67539c2
TL
825 int verify_permission(optional_yield y) override;
826 void execute(optional_yield y) override;
7c673cae 827
f67539c2 828 virtual int get_params(optional_yield y) = 0;
20effc67 829 virtual void handle_listing_chunk(rgw::sal::BucketList&& buckets) {
3efd9988
FG
830 /* The default implementation, used by e.g. S3, just generates a new
831 * part of listing and sends it client immediately. Swift can behave
832 * differently: when the reverse option is requested, all incoming
9f95a23c 833 * instances of RGWBucketList are buffered and finally reversed. */
3efd9988
FG
834 return send_response_data(buckets);
835 }
7c673cae 836 virtual void send_response_begin(bool has_buckets) = 0;
20effc67 837 virtual void send_response_data(rgw::sal::BucketList& buckets) = 0;
7c673cae
FG
838 virtual void send_response_end() = 0;
839 void send_response() override {}
840
841 virtual bool should_get_stats() { return false; }
842 virtual bool supports_account_metadata() { return false; }
843
11fdf7f2 844 const char* name() const override { return "list_buckets"; }
7c673cae
FG
845 RGWOpType get_type() override { return RGW_OP_LIST_BUCKETS; }
846 uint32_t op_mask() override { return RGW_OP_TYPE_READ; }
1adf2230 847}; // class RGWListBuckets
7c673cae
FG
848
849class RGWGetUsage : public RGWOp {
850protected:
851 bool sent_data;
20effc67
TL
852 std::string start_date;
853 std::string end_date;
7c673cae
FG
854 int show_log_entries;
855 int show_log_sum;
20effc67
TL
856 std::map<std::string, bool> categories;
857 std::map<rgw_user_bucket, rgw_usage_log_entry> usage;
858 std::map<std::string, rgw_usage_log_entry> summary_map;
859 std::map<std::string, bucket_meta_entry> buckets_usage;
7c673cae 860 cls_user_header header;
9f95a23c 861 RGWStorageStats stats;
7c673cae
FG
862public:
863 RGWGetUsage() : sent_data(false), show_log_entries(true), show_log_sum(true){
864 }
865
f67539c2
TL
866 int verify_permission(optional_yield y) override;
867 void execute(optional_yield y) override;
7c673cae 868
f67539c2 869 virtual int get_params(optional_yield y) = 0;
7c673cae
FG
870 void send_response() override {}
871
872 virtual bool should_get_stats() { return false; }
873
9f95a23c 874 const char* name() const override { return "get_self_usage"; }
7c673cae
FG
875 uint32_t op_mask() override { return RGW_OP_TYPE_READ; }
876};
877
878class RGWStatAccount : public RGWOp {
879protected:
3efd9988
FG
880 RGWUsageStats global_stats;
881 std::map<std::string, RGWUsageStats> policies_stats;
7c673cae
FG
882
883public:
3efd9988 884 RGWStatAccount() = default;
7c673cae 885
f67539c2
TL
886 int verify_permission(optional_yield y) override;
887 void execute(optional_yield y) override;
7c673cae
FG
888
889 void send_response() override = 0;
11fdf7f2 890 const char* name() const override { return "stat_account"; }
7c673cae
FG
891 RGWOpType get_type() override { return RGW_OP_STAT_ACCOUNT; }
892 uint32_t op_mask() override { return RGW_OP_TYPE_READ; }
893};
894
895class RGWListBucket : public RGWOp {
896protected:
20effc67 897 std::string prefix;
7c673cae
FG
898 rgw_obj_key marker;
899 rgw_obj_key next_marker;
900 rgw_obj_key end_marker;
20effc67
TL
901 std::string max_keys;
902 std::string delimiter;
903 std::string encoding_type;
7c673cae
FG
904 bool list_versions;
905 int max;
20effc67
TL
906 std::vector<rgw_bucket_dir_entry> objs;
907 std::map<std::string, bool> common_prefixes;
7c673cae
FG
908
909 int default_max;
910 bool is_truncated;
1adf2230 911 bool allow_unordered;
7c673cae
FG
912
913 int shard_id;
914
915 int parse_max_keys();
916
917public:
f67539c2 918 RGWListBucket() : list_versions(false), max(0),
1adf2230
AA
919 default_max(0), is_truncated(false),
920 allow_unordered(false), shard_id(-1) {}
f67539c2 921 int verify_permission(optional_yield y) override;
7c673cae 922 void pre_exec() override;
f67539c2 923 void execute(optional_yield y) override;
7c673cae 924
20effc67 925 void init(rgw::sal::Store* store, struct req_state *s, RGWHandler *h) override {
9f95a23c 926 RGWOp::init(store, s, h);
9f95a23c 927 }
f67539c2 928 virtual int get_params(optional_yield y) = 0;
7c673cae 929 void send_response() override = 0;
11fdf7f2 930 const char* name() const override { return "list_bucket"; }
7c673cae
FG
931 RGWOpType get_type() override { return RGW_OP_LIST_BUCKET; }
932 uint32_t op_mask() override { return RGW_OP_TYPE_READ; }
933 virtual bool need_container_stats() { return false; }
934};
935
936class RGWGetBucketLogging : public RGWOp {
937public:
938 RGWGetBucketLogging() {}
f67539c2
TL
939 int verify_permission(optional_yield y) override;
940 void execute(optional_yield) override { }
7c673cae
FG
941
942 void send_response() override = 0;
11fdf7f2 943 const char* name() const override { return "get_bucket_logging"; }
7c673cae
FG
944 RGWOpType get_type() override { return RGW_OP_GET_BUCKET_LOGGING; }
945 uint32_t op_mask() override { return RGW_OP_TYPE_READ; }
946};
947
948class RGWGetBucketLocation : public RGWOp {
949public:
950 RGWGetBucketLocation() {}
951 ~RGWGetBucketLocation() override {}
f67539c2
TL
952 int verify_permission(optional_yield y) override;
953 void execute(optional_yield) override { }
7c673cae
FG
954
955 void send_response() override = 0;
11fdf7f2 956 const char* name() const override { return "get_bucket_location"; }
3efd9988 957 RGWOpType get_type() override { return RGW_OP_GET_BUCKET_LOCATION; }
7c673cae
FG
958 uint32_t op_mask() override { return RGW_OP_TYPE_READ; }
959};
960
961class RGWGetBucketVersioning : public RGWOp {
962protected:
11fdf7f2
TL
963 bool versioned{false};
964 bool versioning_enabled{false};
965 bool mfa_enabled{false};
7c673cae 966public:
11fdf7f2 967 RGWGetBucketVersioning() = default;
7c673cae 968
f67539c2 969 int verify_permission(optional_yield y) override;
7c673cae 970 void pre_exec() override;
f67539c2 971 void execute(optional_yield y) override;
7c673cae
FG
972
973 void send_response() override = 0;
11fdf7f2 974 const char* name() const override { return "get_bucket_versioning"; }
7c673cae
FG
975 RGWOpType get_type() override { return RGW_OP_GET_BUCKET_VERSIONING; }
976 uint32_t op_mask() override { return RGW_OP_TYPE_READ; }
977};
978
11fdf7f2
TL
979enum BucketVersionStatus {
980 VersioningStatusInvalid = -1,
981 VersioningNotChanged = 0,
982 VersioningEnabled = 1,
983 VersioningSuspended =2,
984};
985
7c673cae
FG
986class RGWSetBucketVersioning : public RGWOp {
987protected:
11fdf7f2
TL
988 int versioning_status;
989 bool mfa_set_status{false};
990 bool mfa_status{false};
7c673cae
FG
991 bufferlist in_data;
992public:
11fdf7f2 993 RGWSetBucketVersioning() : versioning_status(VersioningNotChanged) {}
7c673cae 994
f67539c2 995 int verify_permission(optional_yield y) override;
7c673cae 996 void pre_exec() override;
f67539c2 997 void execute(optional_yield y) override;
7c673cae 998
f67539c2 999 virtual int get_params(optional_yield y) { return 0; }
7c673cae
FG
1000
1001 void send_response() override = 0;
11fdf7f2 1002 const char* name() const override { return "set_bucket_versioning"; }
7c673cae
FG
1003 RGWOpType get_type() override { return RGW_OP_SET_BUCKET_VERSIONING; }
1004 uint32_t op_mask() override { return RGW_OP_TYPE_WRITE; }
1005};
1006
1007class RGWGetBucketWebsite : public RGWOp {
1008public:
1009 RGWGetBucketWebsite() {}
1010
f67539c2 1011 int verify_permission(optional_yield y) override;
7c673cae 1012 void pre_exec() override;
f67539c2 1013 void execute(optional_yield y) override;
7c673cae
FG
1014
1015 void send_response() override = 0;
11fdf7f2 1016 const char* name() const override { return "get_bucket_website"; }
7c673cae
FG
1017 RGWOpType get_type() override { return RGW_OP_GET_BUCKET_WEBSITE; }
1018 uint32_t op_mask() override { return RGW_OP_TYPE_READ; }
1019};
1020
1021class RGWSetBucketWebsite : public RGWOp {
1022protected:
31f18b77 1023 bufferlist in_data;
7c673cae
FG
1024 RGWBucketWebsiteConf website_conf;
1025public:
1026 RGWSetBucketWebsite() {}
1027
f67539c2 1028 int verify_permission(optional_yield y) override;
7c673cae 1029 void pre_exec() override;
f67539c2 1030 void execute(optional_yield y) override;
7c673cae 1031
f67539c2 1032 virtual int get_params(optional_yield y) { return 0; }
7c673cae
FG
1033
1034 void send_response() override = 0;
11fdf7f2 1035 const char* name() const override { return "set_bucket_website"; }
7c673cae
FG
1036 RGWOpType get_type() override { return RGW_OP_SET_BUCKET_WEBSITE; }
1037 uint32_t op_mask() override { return RGW_OP_TYPE_WRITE; }
1038};
1039
1040class RGWDeleteBucketWebsite : public RGWOp {
1041public:
1042 RGWDeleteBucketWebsite() {}
1043
f67539c2 1044 int verify_permission(optional_yield y) override;
7c673cae 1045 void pre_exec() override;
f67539c2 1046 void execute(optional_yield y) override;
7c673cae
FG
1047
1048 void send_response() override = 0;
11fdf7f2 1049 const char* name() const override { return "delete_bucket_website"; }
7c673cae
FG
1050 RGWOpType get_type() override { return RGW_OP_SET_BUCKET_WEBSITE; }
1051 uint32_t op_mask() override { return RGW_OP_TYPE_WRITE; }
1052};
1053
1054class RGWStatBucket : public RGWOp {
1055protected:
20effc67 1056 std::unique_ptr<rgw::sal::Bucket> bucket;
7c673cae
FG
1057
1058public:
f67539c2 1059 int verify_permission(optional_yield y) override;
7c673cae 1060 void pre_exec() override;
f67539c2 1061 void execute(optional_yield y) override;
7c673cae
FG
1062
1063 void send_response() override = 0;
11fdf7f2 1064 const char* name() const override { return "stat_bucket"; }
7c673cae
FG
1065 RGWOpType get_type() override { return RGW_OP_STAT_BUCKET; }
1066 uint32_t op_mask() override { return RGW_OP_TYPE_READ; }
1067};
1068
1069class RGWCreateBucket : public RGWOp {
1070protected:
1071 RGWAccessControlPolicy policy;
20effc67 1072 std::string location_constraint;
11fdf7f2 1073 rgw_placement_rule placement_rule;
7c673cae
FG
1074 RGWBucketInfo info;
1075 obj_version ep_objv;
1076 bool has_cors;
11fdf7f2 1077 bool relaxed_region_enforcement;
eafe8130 1078 bool obj_lock_enabled;
7c673cae
FG
1079 RGWCORSConfiguration cors_config;
1080 boost::optional<std::string> swift_ver_location;
20effc67
TL
1081 std::map<std::string, buffer::list> attrs;
1082 std::set<std::string> rmattr_names;
7c673cae
FG
1083
1084 bufferlist in_data;
1085
1086 virtual bool need_metadata_upload() const { return false; }
1087
1088public:
eafe8130 1089 RGWCreateBucket() : has_cors(false), relaxed_region_enforcement(false), obj_lock_enabled(false) {}
7c673cae
FG
1090
1091 void emplace_attr(std::string&& key, buffer::list&& bl) {
1092 attrs.emplace(std::move(key), std::move(bl)); /* key and bl are r-value refs */
1093 }
1094
f67539c2 1095 int verify_permission(optional_yield y) override;
7c673cae 1096 void pre_exec() override;
f67539c2 1097 void execute(optional_yield y) override;
20effc67 1098 void init(rgw::sal::Store* store, struct req_state *s, RGWHandler *h) override {
7c673cae
FG
1099 RGWOp::init(store, s, h);
1100 policy.set_ctx(s->cct);
11fdf7f2
TL
1101 relaxed_region_enforcement =
1102 s->cct->_conf.get_val<bool>("rgw_relaxed_region_enforcement");
7c673cae 1103 }
f67539c2 1104 virtual int get_params(optional_yield y) { return 0; }
7c673cae 1105 void send_response() override = 0;
11fdf7f2 1106 const char* name() const override { return "create_bucket"; }
7c673cae
FG
1107 RGWOpType get_type() override { return RGW_OP_CREATE_BUCKET; }
1108 uint32_t op_mask() override { return RGW_OP_TYPE_WRITE; }
1109};
1110
1111class RGWDeleteBucket : public RGWOp {
1112protected:
1113 RGWObjVersionTracker objv_tracker;
1114
1115public:
1116 RGWDeleteBucket() {}
1117
f67539c2 1118 int verify_permission(optional_yield y) override;
7c673cae 1119 void pre_exec() override;
f67539c2 1120 void execute(optional_yield y) override;
7c673cae
FG
1121
1122 void send_response() override = 0;
11fdf7f2 1123 const char* name() const override { return "delete_bucket"; }
7c673cae
FG
1124 RGWOpType get_type() override { return RGW_OP_DELETE_BUCKET; }
1125 uint32_t op_mask() override { return RGW_OP_TYPE_DELETE; }
1126};
1127
1128struct rgw_slo_entry {
20effc67
TL
1129 std::string path;
1130 std::string etag;
7c673cae
FG
1131 uint64_t size_bytes;
1132
1133 rgw_slo_entry() : size_bytes(0) {}
1134
1135 void encode(bufferlist& bl) const {
1136 ENCODE_START(1, 1, bl);
11fdf7f2
TL
1137 encode(path, bl);
1138 encode(etag, bl);
1139 encode(size_bytes, bl);
7c673cae
FG
1140 ENCODE_FINISH(bl);
1141 }
1142
11fdf7f2 1143 void decode(bufferlist::const_iterator& bl) {
7c673cae 1144 DECODE_START(1, bl);
11fdf7f2
TL
1145 decode(path, bl);
1146 decode(etag, bl);
1147 decode(size_bytes, bl);
7c673cae
FG
1148 DECODE_FINISH(bl);
1149 }
1150
1151 void decode_json(JSONObj *obj);
1152};
1153WRITE_CLASS_ENCODER(rgw_slo_entry)
1154
1155struct RGWSLOInfo {
20effc67 1156 std::vector<rgw_slo_entry> entries;
7c673cae
FG
1157 uint64_t total_size;
1158
1159 /* in memory only */
11fdf7f2 1160 bufferlist raw_data;
7c673cae 1161
11fdf7f2
TL
1162 RGWSLOInfo() : total_size(0) {}
1163 ~RGWSLOInfo() {}
7c673cae
FG
1164
1165 void encode(bufferlist& bl) const {
1166 ENCODE_START(1, 1, bl);
11fdf7f2
TL
1167 encode(entries, bl);
1168 encode(total_size, bl);
7c673cae
FG
1169 ENCODE_FINISH(bl);
1170 }
1171
11fdf7f2 1172 void decode(bufferlist::const_iterator& bl) {
7c673cae 1173 DECODE_START(1, bl);
11fdf7f2
TL
1174 decode(entries, bl);
1175 decode(total_size, bl);
7c673cae
FG
1176 DECODE_FINISH(bl);
1177 }
1178};
1179WRITE_CLASS_ENCODER(RGWSLOInfo)
1180
1181class RGWPutObj : public RGWOp {
7c673cae
FG
1182protected:
1183 seed torrent;
1184 off_t ofs;
1185 const char *supplied_md5_b64;
1186 const char *supplied_etag;
1187 const char *if_match;
1188 const char *if_nomatch;
3a9019d9 1189 std::string copy_source;
7c673cae
FG
1190 const char *copy_source_range;
1191 RGWBucketInfo copy_source_bucket_info;
20effc67
TL
1192 std::string copy_source_tenant_name;
1193 std::string copy_source_bucket_name;
1194 std::string copy_source_object_name;
1195 std::string copy_source_version_id;
7c673cae
FG
1196 off_t copy_source_range_fst;
1197 off_t copy_source_range_lst;
20effc67 1198 std::string etag;
7c673cae
FG
1199 bool chunked_upload;
1200 RGWAccessControlPolicy policy;
224ce89b 1201 std::unique_ptr <RGWObjTags> obj_tags;
7c673cae
FG
1202 const char *dlo_manifest;
1203 RGWSLOInfo *slo_info;
20effc67 1204 rgw::sal::Attrs attrs;
7c673cae
FG
1205 ceph::real_time mtime;
1206 uint64_t olh_epoch;
20effc67 1207 std::string version_id;
7c673cae 1208 bufferlist bl_aux;
20effc67
TL
1209 std::map<std::string, std::string> crypt_http_responses;
1210 std::string user_data;
7c673cae 1211
11fdf7f2
TL
1212 std::string multipart_upload_id;
1213 std::string multipart_part_str;
1214 int multipart_part_num = 0;
20effc67 1215 jspan multipart_trace;
11fdf7f2 1216
7c673cae 1217 boost::optional<ceph::real_time> delete_at;
11fdf7f2
TL
1218 //append obj
1219 bool append;
1220 uint64_t position;
1221 uint64_t cur_accounted_size;
7c673cae 1222
eafe8130
TL
1223 //object lock
1224 RGWObjectRetention *obj_retention;
1225 RGWObjectLegalHold *obj_legal_hold;
1226
7c673cae
FG
1227public:
1228 RGWPutObj() : ofs(0),
1229 supplied_md5_b64(NULL),
1230 supplied_etag(NULL),
1231 if_match(NULL),
1232 if_nomatch(NULL),
7c673cae
FG
1233 copy_source_range(NULL),
1234 copy_source_range_fst(0),
1235 copy_source_range_lst(0),
1236 chunked_upload(0),
1237 dlo_manifest(NULL),
1238 slo_info(NULL),
11fdf7f2
TL
1239 olh_epoch(0),
1240 append(false),
1241 position(0),
eafe8130
TL
1242 cur_accounted_size(0),
1243 obj_retention(nullptr),
1244 obj_legal_hold(nullptr) {}
7c673cae
FG
1245
1246 ~RGWPutObj() override {
1247 delete slo_info;
eafe8130
TL
1248 delete obj_retention;
1249 delete obj_legal_hold;
7c673cae
FG
1250 }
1251
20effc67 1252 void init(rgw::sal::Store* store, struct req_state *s, RGWHandler *h) override {
7c673cae
FG
1253 RGWOp::init(store, s, h);
1254 policy.set_ctx(s->cct);
1255 }
1256
f67539c2
TL
1257 virtual int init_processing(optional_yield y) override;
1258
7c673cae
FG
1259 void emplace_attr(std::string&& key, buffer::list&& bl) {
1260 attrs.emplace(std::move(key), std::move(bl)); /* key and bl are r-value refs */
1261 }
1262
f67539c2 1263 int verify_permission(optional_yield y) override;
7c673cae 1264 void pre_exec() override;
f67539c2 1265 void execute(optional_yield y) override;
7c673cae
FG
1266
1267 /* this is for cases when copying data from other object */
11fdf7f2
TL
1268 virtual int get_decrypt_filter(std::unique_ptr<RGWGetObj_Filter>* filter,
1269 RGWGetObj_Filter* cb,
20effc67 1270 std::map<std::string, bufferlist>& attrs,
7c673cae
FG
1271 bufferlist* manifest_bl) {
1272 *filter = nullptr;
1273 return 0;
1274 }
20effc67
TL
1275 virtual int get_encrypt_filter(std::unique_ptr<rgw::sal::DataProcessor> *filter,
1276 rgw::sal::DataProcessor *cb) {
11fdf7f2 1277 return 0;
7c673cae
FG
1278 }
1279
1280 int get_data_cb(bufferlist& bl, off_t bl_ofs, off_t bl_len);
1281 int get_data(const off_t fst, const off_t lst, bufferlist& bl);
1282
f67539c2 1283 virtual int get_params(optional_yield y) = 0;
7c673cae
FG
1284 virtual int get_data(bufferlist& bl) = 0;
1285 void send_response() override = 0;
11fdf7f2 1286 const char* name() const override { return "put_obj"; }
7c673cae
FG
1287 RGWOpType get_type() override { return RGW_OP_PUT_OBJ; }
1288 uint32_t op_mask() override { return RGW_OP_TYPE_WRITE; }
11fdf7f2 1289 dmc::client_id dmclock_client() override { return dmc::client_id::data; }
7c673cae
FG
1290};
1291
7c673cae
FG
1292class RGWPostObj : public RGWOp {
1293protected:
1294 off_t min_len;
1295 off_t max_len;
1296 int len;
1297 off_t ofs;
1298 const char *supplied_md5_b64;
1299 const char *supplied_etag;
20effc67 1300 std::string etag;
7c673cae 1301 RGWAccessControlPolicy policy;
20effc67 1302 std::map<std::string, bufferlist> attrs;
7c673cae
FG
1303 boost::optional<ceph::real_time> delete_at;
1304
1305 /* Must be called after get_data() or the result is undefined. */
1306 virtual std::string get_current_filename() const = 0;
1307 virtual std::string get_current_content_type() const = 0;
1308 virtual bool is_next_file_to_upload() {
1309 return false;
1310 }
1311public:
1312 RGWPostObj() : min_len(0),
1313 max_len(LLONG_MAX),
1314 len(0),
1315 ofs(0),
1316 supplied_md5_b64(nullptr),
1317 supplied_etag(nullptr) {
1318 }
1319
1320 void emplace_attr(std::string&& key, buffer::list&& bl) {
1321 attrs.emplace(std::move(key), std::move(bl)); /* key and bl are r-value refs */
1322 }
1323
20effc67 1324 void init(rgw::sal::Store* store, struct req_state *s, RGWHandler *h) override {
7c673cae
FG
1325 RGWOp::init(store, s, h);
1326 policy.set_ctx(s->cct);
1327 }
1328
f67539c2 1329 int verify_permission(optional_yield y) override;
7c673cae 1330 void pre_exec() override;
f67539c2 1331 void execute(optional_yield y) override;
7c673cae 1332
20effc67
TL
1333 virtual int get_encrypt_filter(std::unique_ptr<rgw::sal::DataProcessor> *filter,
1334 rgw::sal::DataProcessor *cb) {
7c673cae
FG
1335 return 0;
1336 }
f67539c2 1337 virtual int get_params(optional_yield y) = 0;
7c673cae
FG
1338 virtual int get_data(ceph::bufferlist& bl, bool& again) = 0;
1339 void send_response() override = 0;
11fdf7f2 1340 const char* name() const override { return "post_obj"; }
7c673cae
FG
1341 RGWOpType get_type() override { return RGW_OP_POST_OBJ; }
1342 uint32_t op_mask() override { return RGW_OP_TYPE_WRITE; }
11fdf7f2 1343 dmc::client_id dmclock_client() override { return dmc::client_id::data; }
7c673cae
FG
1344};
1345
1346class RGWPutMetadataAccount : public RGWOp {
1347protected:
1348 std::set<std::string> rmattr_names;
1349 std::map<std::string, bufferlist> attrs, orig_attrs;
1350 std::map<int, std::string> temp_url_keys;
1351 RGWQuotaInfo new_quota;
1352 bool new_quota_extracted;
1353
7c673cae
FG
1354 RGWAccessControlPolicy policy;
1355 bool has_policy;
1356
1357public:
1358 RGWPutMetadataAccount()
1359 : new_quota_extracted(false),
1360 has_policy(false) {
1361 }
1362
20effc67 1363 void init(rgw::sal::Store* store, struct req_state *s, RGWHandler *h) override {
7c673cae
FG
1364 RGWOp::init(store, s, h);
1365 policy.set_ctx(s->cct);
1366 }
f67539c2
TL
1367 int init_processing(optional_yield y) override;
1368 int verify_permission(optional_yield y) override;
7c673cae 1369 void pre_exec() override { }
f67539c2 1370 void execute(optional_yield y) override;
7c673cae 1371
f67539c2 1372 virtual int get_params(optional_yield y) = 0;
7c673cae 1373 void send_response() override = 0;
20effc67
TL
1374 virtual void filter_out_temp_url(std::map<std::string, bufferlist>& add_attrs,
1375 const std::set<std::string>& rmattr_names,
1376 std::map<int, std::string>& temp_url_keys);
11fdf7f2 1377 const char* name() const override { return "put_account_metadata"; }
7c673cae
FG
1378 RGWOpType get_type() override { return RGW_OP_PUT_METADATA_ACCOUNT; }
1379 uint32_t op_mask() override { return RGW_OP_TYPE_WRITE; }
1380};
1381
1382class RGWPutMetadataBucket : public RGWOp {
1383protected:
20effc67
TL
1384 rgw::sal::Attrs attrs;
1385 std::set<std::string> rmattr_names;
7c673cae
FG
1386 bool has_policy, has_cors;
1387 uint32_t policy_rw_mask;
1388 RGWAccessControlPolicy policy;
1389 RGWCORSConfiguration cors_config;
11fdf7f2 1390 rgw_placement_rule placement_rule;
7c673cae
FG
1391 boost::optional<std::string> swift_ver_location;
1392
1393public:
1394 RGWPutMetadataBucket()
1395 : has_policy(false), has_cors(false), policy_rw_mask(0)
1396 {}
1397
1398 void emplace_attr(std::string&& key, buffer::list&& bl) {
1399 attrs.emplace(std::move(key), std::move(bl)); /* key and bl are r-value refs */
1400 }
1401
20effc67 1402 void init(rgw::sal::Store* store, struct req_state *s, RGWHandler *h) override {
7c673cae
FG
1403 RGWOp::init(store, s, h);
1404 policy.set_ctx(s->cct);
1405 }
1406
f67539c2 1407 int verify_permission(optional_yield y) override;
7c673cae 1408 void pre_exec() override;
f67539c2 1409 void execute(optional_yield y) override;
7c673cae 1410
f67539c2 1411 virtual int get_params(optional_yield y) = 0;
7c673cae 1412 void send_response() override = 0;
11fdf7f2 1413 const char* name() const override { return "put_bucket_metadata"; }
7c673cae
FG
1414 RGWOpType get_type() override { return RGW_OP_PUT_METADATA_BUCKET; }
1415 uint32_t op_mask() override { return RGW_OP_TYPE_WRITE; }
1416};
1417
1418class RGWPutMetadataObject : public RGWOp {
1419protected:
1420 RGWAccessControlPolicy policy;
7c673cae
FG
1421 boost::optional<ceph::real_time> delete_at;
1422 const char *dlo_manifest;
1423
1424public:
1425 RGWPutMetadataObject()
1426 : dlo_manifest(NULL)
1427 {}
1428
20effc67 1429 void init(rgw::sal::Store* store, struct req_state *s, RGWHandler *h) override {
7c673cae
FG
1430 RGWOp::init(store, s, h);
1431 policy.set_ctx(s->cct);
1432 }
f67539c2 1433 int verify_permission(optional_yield y) override;
7c673cae 1434 void pre_exec() override;
f67539c2 1435 void execute(optional_yield y) override;
7c673cae 1436
f67539c2 1437 virtual int get_params(optional_yield y) = 0;
7c673cae 1438 void send_response() override = 0;
11fdf7f2 1439 const char* name() const override { return "put_obj_metadata"; }
7c673cae
FG
1440 RGWOpType get_type() override { return RGW_OP_PUT_METADATA_OBJECT; }
1441 uint32_t op_mask() override { return RGW_OP_TYPE_WRITE; }
1442 virtual bool need_object_expiration() { return false; }
1443};
1444
1445class RGWDeleteObj : public RGWOp {
1446protected:
1447 bool delete_marker;
1448 bool multipart_delete;
20effc67 1449 std::string version_id;
7c673cae
FG
1450 ceph::real_time unmod_since; /* if unmodified since */
1451 bool no_precondition_error;
1452 std::unique_ptr<RGWBulkDelete::Deleter> deleter;
eafe8130
TL
1453 bool bypass_perm;
1454 bool bypass_governance_mode;
7c673cae
FG
1455
1456public:
1457 RGWDeleteObj()
1458 : delete_marker(false),
1459 multipart_delete(false),
1460 no_precondition_error(false),
eafe8130
TL
1461 deleter(nullptr),
1462 bypass_perm(true),
1463 bypass_governance_mode(false) {
7c673cae
FG
1464 }
1465
f67539c2 1466 int verify_permission(optional_yield y) override;
7c673cae 1467 void pre_exec() override;
f67539c2
TL
1468 void execute(optional_yield y) override;
1469 int handle_slo_manifest(bufferlist& bl, optional_yield y);
7c673cae 1470
f67539c2 1471 virtual int get_params(optional_yield y) { return 0; }
7c673cae 1472 void send_response() override = 0;
11fdf7f2 1473 const char* name() const override { return "delete_obj"; }
7c673cae
FG
1474 RGWOpType get_type() override { return RGW_OP_DELETE_OBJ; }
1475 uint32_t op_mask() override { return RGW_OP_TYPE_DELETE; }
1476 virtual bool need_object_expiration() { return false; }
11fdf7f2 1477 dmc::client_id dmclock_client() override { return dmc::client_id::data; }
7c673cae
FG
1478};
1479
1480class RGWCopyObj : public RGWOp {
1481protected:
1482 RGWAccessControlPolicy dest_policy;
1483 const char *if_mod;
1484 const char *if_unmod;
1485 const char *if_match;
1486 const char *if_nomatch;
494da23a
TL
1487 // Required or it is not a copy operation
1488 std::string_view copy_source;
1489 // Not actually required
1490 std::optional<std::string_view> md_directive;
11fdf7f2 1491
7c673cae
FG
1492 off_t ofs;
1493 off_t len;
1494 off_t end;
1495 ceph::real_time mod_time;
1496 ceph::real_time unmod_time;
1497 ceph::real_time *mod_ptr;
1498 ceph::real_time *unmod_ptr;
20effc67
TL
1499 rgw::sal::Attrs attrs;
1500 std::string src_tenant_name, src_bucket_name, src_obj_name;
1501 std::unique_ptr<rgw::sal::Bucket> src_bucket;
1502 std::string dest_tenant_name, dest_bucket_name, dest_obj_name;
1503 std::unique_ptr<rgw::sal::Bucket> dest_bucket;
1504 std::unique_ptr<rgw::sal::Object> dest_object;
7c673cae
FG
1505 ceph::real_time src_mtime;
1506 ceph::real_time mtime;
f67539c2 1507 rgw::sal::AttrsMod attrs_mod;
20effc67
TL
1508 std::string source_zone;
1509 std::string etag;
7c673cae
FG
1510
1511 off_t last_ofs;
1512
20effc67 1513 std::string version_id;
7c673cae
FG
1514 uint64_t olh_epoch;
1515
1516 boost::optional<ceph::real_time> delete_at;
1517 bool copy_if_newer;
1518
11fdf7f2
TL
1519 bool need_to_check_storage_class = false;
1520
20effc67
TL
1521 //object lock
1522 RGWObjectRetention *obj_retention;
1523 RGWObjectLegalHold *obj_legal_hold;
1524
7c673cae
FG
1525 int init_common();
1526
1527public:
1528 RGWCopyObj() {
1529 if_mod = NULL;
1530 if_unmod = NULL;
1531 if_match = NULL;
1532 if_nomatch = NULL;
1533 ofs = 0;
1534 len = 0;
1535 end = -1;
1536 mod_ptr = NULL;
1537 unmod_ptr = NULL;
f67539c2 1538 attrs_mod = rgw::sal::ATTRSMOD_NONE;
7c673cae
FG
1539 last_ofs = 0;
1540 olh_epoch = 0;
1541 copy_if_newer = false;
20effc67
TL
1542 obj_retention = nullptr;
1543 obj_legal_hold = nullptr;
1544 }
1545
1546 ~RGWCopyObj() override {
1547 delete obj_retention;
1548 delete obj_legal_hold;
7c673cae
FG
1549 }
1550
f67539c2 1551 static bool parse_copy_location(const std::string_view& src,
20effc67 1552 std::string& bucket_name,
b3b6e05e
TL
1553 rgw_obj_key& object,
1554 struct req_state *s);
7c673cae
FG
1555
1556 void emplace_attr(std::string&& key, buffer::list&& bl) {
1557 attrs.emplace(std::move(key), std::move(bl));
1558 }
1559
20effc67 1560 void init(rgw::sal::Store* store, struct req_state *s, RGWHandler *h) override {
7c673cae
FG
1561 RGWOp::init(store, s, h);
1562 dest_policy.set_ctx(s->cct);
1563 }
f67539c2 1564 int verify_permission(optional_yield y) override;
7c673cae 1565 void pre_exec() override;
f67539c2 1566 void execute(optional_yield y) override;
7c673cae
FG
1567 void progress_cb(off_t ofs);
1568
11fdf7f2
TL
1569 virtual int check_storage_class(const rgw_placement_rule& src_placement) {
1570 return 0;
1571 }
1572
7c673cae 1573 virtual int init_dest_policy() { return 0; }
f67539c2 1574 virtual int get_params(optional_yield y) = 0;
7c673cae
FG
1575 virtual void send_partial_response(off_t ofs) {}
1576 void send_response() override = 0;
11fdf7f2 1577 const char* name() const override { return "copy_obj"; }
7c673cae
FG
1578 RGWOpType get_type() override { return RGW_OP_COPY_OBJ; }
1579 uint32_t op_mask() override { return RGW_OP_TYPE_WRITE; }
11fdf7f2 1580 dmc::client_id dmclock_client() override { return dmc::client_id::data; }
7c673cae
FG
1581};
1582
1583class RGWGetACLs : public RGWOp {
1584protected:
20effc67 1585 std::string acls;
7c673cae
FG
1586
1587public:
1588 RGWGetACLs() {}
1589
f67539c2 1590 int verify_permission(optional_yield y) override;
7c673cae 1591 void pre_exec() override;
f67539c2 1592 void execute(optional_yield y) override;
7c673cae
FG
1593
1594 void send_response() override = 0;
11fdf7f2 1595 const char* name() const override { return "get_acls"; }
7c673cae
FG
1596 RGWOpType get_type() override { return RGW_OP_GET_ACLS; }
1597 uint32_t op_mask() override { return RGW_OP_TYPE_READ; }
1598};
1599
1600class RGWPutACLs : public RGWOp {
1601protected:
11fdf7f2 1602 bufferlist data;
7c673cae
FG
1603 ACLOwner owner;
1604
1605public:
11fdf7f2
TL
1606 RGWPutACLs() {}
1607 ~RGWPutACLs() override {}
7c673cae 1608
f67539c2 1609 int verify_permission(optional_yield y) override;
7c673cae 1610 void pre_exec() override;
f67539c2 1611 void execute(optional_yield y) override;
7c673cae 1612
20effc67 1613 virtual int get_policy_from_state(rgw::sal::Store* store, struct req_state *s, std::stringstream& ss) { return 0; }
f67539c2 1614 virtual int get_params(optional_yield y) = 0;
7c673cae 1615 void send_response() override = 0;
11fdf7f2 1616 const char* name() const override { return "put_acls"; }
7c673cae
FG
1617 RGWOpType get_type() override { return RGW_OP_PUT_ACLS; }
1618 uint32_t op_mask() override { return RGW_OP_TYPE_WRITE; }
1619};
1620
1621class RGWGetLC : public RGWOp {
1622protected:
1623
1624public:
1625 RGWGetLC() { }
1626 ~RGWGetLC() override { }
1627
f67539c2 1628 int verify_permission(optional_yield y) override;
7c673cae 1629 void pre_exec() override;
f67539c2 1630 void execute(optional_yield) override = 0;
7c673cae
FG
1631
1632 void send_response() override = 0;
11fdf7f2 1633 const char* name() const override { return "get_lifecycle"; }
d2e6a577 1634 RGWOpType get_type() override { return RGW_OP_GET_LC; }
7c673cae
FG
1635 uint32_t op_mask() override { return RGW_OP_TYPE_READ; }
1636};
1637
1638class RGWPutLC : public RGWOp {
1639protected:
11fdf7f2 1640 bufferlist data;
b32b8144 1641 const char *content_md5;
20effc67 1642 std::string cookie;
7c673cae
FG
1643
1644public:
1645 RGWPutLC() {
b32b8144 1646 content_md5 = nullptr;
7c673cae 1647 }
11fdf7f2 1648 ~RGWPutLC() override {}
7c673cae 1649
20effc67 1650 void init(rgw::sal::Store* store, struct req_state *s, RGWHandler *dialect_handler) override {
7c673cae
FG
1651#define COOKIE_LEN 16
1652 char buf[COOKIE_LEN + 1];
1653
1654 RGWOp::init(store, s, dialect_handler);
1655 gen_rand_alphanumeric(s->cct, buf, sizeof(buf) - 1);
1656 cookie = buf;
1657 }
1658
f67539c2 1659 int verify_permission(optional_yield y) override;
7c673cae 1660 void pre_exec() override;
f67539c2 1661 void execute(optional_yield y) override;
7c673cae 1662
20effc67 1663// virtual int get_policy_from_state(RGWRados* store, struct req_state *s, std::stringstream& ss) { return 0; }
f67539c2 1664 virtual int get_params(optional_yield y) = 0;
7c673cae 1665 void send_response() override = 0;
11fdf7f2 1666 const char* name() const override { return "put_lifecycle"; }
d2e6a577 1667 RGWOpType get_type() override { return RGW_OP_PUT_LC; }
7c673cae
FG
1668 uint32_t op_mask() override { return RGW_OP_TYPE_WRITE; }
1669};
1670
1671class RGWDeleteLC : public RGWOp {
7c673cae 1672public:
9f95a23c 1673 RGWDeleteLC() = default;
f67539c2 1674 int verify_permission(optional_yield y) override;
7c673cae 1675 void pre_exec() override;
f67539c2 1676 void execute(optional_yield y) override;
7c673cae
FG
1677
1678 void send_response() override = 0;
11fdf7f2 1679 const char* name() const override { return "delete_lifecycle"; }
d2e6a577 1680 RGWOpType get_type() override { return RGW_OP_DELETE_LC; }
7c673cae
FG
1681 uint32_t op_mask() override { return RGW_OP_TYPE_WRITE; }
1682};
1683
1684class RGWGetCORS : public RGWOp {
1685protected:
1686
1687public:
1688 RGWGetCORS() {}
1689
f67539c2
TL
1690 int verify_permission(optional_yield y) override;
1691 void execute(optional_yield y) override;
7c673cae
FG
1692
1693 void send_response() override = 0;
11fdf7f2 1694 const char* name() const override { return "get_cors"; }
7c673cae
FG
1695 RGWOpType get_type() override { return RGW_OP_GET_CORS; }
1696 uint32_t op_mask() override { return RGW_OP_TYPE_READ; }
1697};
1698
1699class RGWPutCORS : public RGWOp {
1700protected:
1701 bufferlist cors_bl;
31f18b77 1702 bufferlist in_data;
7c673cae
FG
1703
1704public:
1705 RGWPutCORS() {}
1706 ~RGWPutCORS() override {}
1707
f67539c2
TL
1708 int verify_permission(optional_yield y) override;
1709 void execute(optional_yield y) override;
7c673cae 1710
f67539c2 1711 virtual int get_params(optional_yield y) = 0;
7c673cae 1712 void send_response() override = 0;
11fdf7f2 1713 const char* name() const override { return "put_cors"; }
7c673cae
FG
1714 RGWOpType get_type() override { return RGW_OP_PUT_CORS; }
1715 uint32_t op_mask() override { return RGW_OP_TYPE_WRITE; }
1716};
1717
1718class RGWDeleteCORS : public RGWOp {
1719protected:
1720
1721public:
1722 RGWDeleteCORS() {}
1723
f67539c2
TL
1724 int verify_permission(optional_yield y) override;
1725 void execute(optional_yield y) override;
7c673cae
FG
1726
1727 void send_response() override = 0;
11fdf7f2 1728 const char* name() const override { return "delete_cors"; }
7c673cae
FG
1729 RGWOpType get_type() override { return RGW_OP_DELETE_CORS; }
1730 uint32_t op_mask() override { return RGW_OP_TYPE_WRITE; }
1731};
1732
1733class RGWOptionsCORS : public RGWOp {
1734protected:
1735 RGWCORSRule *rule;
1736 const char *origin, *req_hdrs, *req_meth;
1737
1738public:
1739 RGWOptionsCORS() : rule(NULL), origin(NULL),
1740 req_hdrs(NULL), req_meth(NULL) {
1741 }
1742
f67539c2 1743 int verify_permission(optional_yield y) override {return 0;}
7c673cae 1744 int validate_cors_request(RGWCORSConfiguration *cc);
f67539c2 1745 void execute(optional_yield y) override;
20effc67 1746 void get_response_params(std::string& allowed_hdrs, std::string& exp_hdrs, unsigned *max_age);
7c673cae 1747 void send_response() override = 0;
11fdf7f2 1748 const char* name() const override { return "options_cors"; }
7c673cae
FG
1749 RGWOpType get_type() override { return RGW_OP_OPTIONS_CORS; }
1750 uint32_t op_mask() override { return RGW_OP_TYPE_READ; }
1751};
1752
20effc67
TL
1753class RGWPutBucketEncryption : public RGWOp {
1754protected:
1755 RGWBucketEncryptionConfig bucket_encryption_conf;
1756 bufferlist data;
1757public:
1758 RGWPutBucketEncryption() = default;
1759 ~RGWPutBucketEncryption() {}
1760
1761 int get_params(optional_yield y);
1762 int verify_permission(optional_yield y) override;
1763 void execute(optional_yield y) override;
1764 const char* name() const override { return "put_bucket_encryption"; }
1765 RGWOpType get_type() override { return RGW_OP_PUT_BUCKET_ENCRYPTION; }
1766 uint32_t op_mask() override { return RGW_OP_TYPE_WRITE; }
1767};
1768
1769class RGWGetBucketEncryption : public RGWOp {
1770protected:
1771 RGWBucketEncryptionConfig bucket_encryption_conf;
1772public:
1773 RGWGetBucketEncryption() {}
1774
1775 int get_params(optional_yield y);
1776 int verify_permission(optional_yield y) override;
1777 void execute(optional_yield y) override;
1778 const char* name() const override { return "get_bucket_encryption"; }
1779 RGWOpType get_type() override { return RGW_OP_GET_BUCKET_ENCRYPTION; }
1780 uint32_t op_mask() override { return RGW_OP_TYPE_READ; }
1781};
1782
1783class RGWDeleteBucketEncryption : public RGWOp {
1784protected:
1785 RGWBucketEncryptionConfig bucket_encryption_conf;
1786public:
1787 RGWDeleteBucketEncryption() {}
1788
1789 int get_params(optional_yield y);
1790 int verify_permission(optional_yield y) override;
1791 void execute(optional_yield y) override;
1792 const char* name() const override { return "delete_bucket_encryption"; }
1793 RGWOpType get_type() override { return RGW_OP_DELETE_BUCKET_ENCRYPTION; }
1794 uint32_t op_mask() override { return RGW_OP_TYPE_WRITE; }
1795};
1796
7c673cae
FG
1797class RGWGetRequestPayment : public RGWOp {
1798protected:
1799 bool requester_pays;
1800
1801public:
1802 RGWGetRequestPayment() : requester_pays(0) {}
1803
f67539c2 1804 int verify_permission(optional_yield y) override;
7c673cae 1805 void pre_exec() override;
f67539c2 1806 void execute(optional_yield y) override;
7c673cae
FG
1807
1808 void send_response() override = 0;
11fdf7f2 1809 const char* name() const override { return "get_request_payment"; }
7c673cae
FG
1810 RGWOpType get_type() override { return RGW_OP_GET_REQUEST_PAYMENT; }
1811 uint32_t op_mask() override { return RGW_OP_TYPE_READ; }
1812};
1813
1814class RGWSetRequestPayment : public RGWOp {
1815protected:
1816 bool requester_pays;
494da23a 1817 bufferlist in_data;
7c673cae
FG
1818public:
1819 RGWSetRequestPayment() : requester_pays(false) {}
1820
f67539c2 1821 int verify_permission(optional_yield y) override;
7c673cae 1822 void pre_exec() override;
f67539c2 1823 void execute(optional_yield y) override;
7c673cae 1824
f67539c2 1825 virtual int get_params(optional_yield y) { return 0; }
7c673cae
FG
1826
1827 void send_response() override = 0;
11fdf7f2 1828 const char* name() const override { return "set_request_payment"; }
7c673cae
FG
1829 RGWOpType get_type() override { return RGW_OP_SET_REQUEST_PAYMENT; }
1830 uint32_t op_mask() override { return RGW_OP_TYPE_WRITE; }
1831};
1832
1833class RGWInitMultipart : public RGWOp {
1834protected:
20effc67 1835 std::string upload_id;
7c673cae 1836 RGWAccessControlPolicy policy;
f6b5b4d7 1837 ceph::real_time mtime;
20effc67 1838 jspan multipart_trace;
7c673cae
FG
1839
1840public:
1841 RGWInitMultipart() {}
1842
20effc67
TL
1843 void init(rgw::sal::Store* store, struct req_state *s, RGWHandler *h) override {
1844 multipart_trace = tracing::rgw::tracer.start_trace(tracing::rgw::MULTIPART);
7c673cae
FG
1845 RGWOp::init(store, s, h);
1846 policy.set_ctx(s->cct);
1847 }
f67539c2 1848 int verify_permission(optional_yield y) override;
7c673cae 1849 void pre_exec() override;
f67539c2 1850 void execute(optional_yield y) override;
7c673cae 1851
f67539c2 1852 virtual int get_params(optional_yield y) = 0;
7c673cae 1853 void send_response() override = 0;
11fdf7f2 1854 const char* name() const override { return "init_multipart"; }
7c673cae
FG
1855 RGWOpType get_type() override { return RGW_OP_INIT_MULTIPART; }
1856 uint32_t op_mask() override { return RGW_OP_TYPE_WRITE; }
20effc67 1857 virtual int prepare_encryption(std::map<std::string, bufferlist>& attrs) { return 0; }
7c673cae
FG
1858};
1859
1860class RGWCompleteMultipart : public RGWOp {
1861protected:
20effc67
TL
1862 std::string upload_id;
1863 std::string etag;
1864 std::string version_id;
11fdf7f2 1865 bufferlist data;
f67539c2 1866 rgw::sal::MPSerializer* serializer;
20effc67 1867 jspan multipart_trace;
3efd9988 1868
7c673cae 1869public:
f67539c2
TL
1870 RGWCompleteMultipart() : serializer(nullptr) {}
1871 ~RGWCompleteMultipart() override { delete serializer; }
7c673cae 1872
f67539c2 1873 int verify_permission(optional_yield y) override;
7c673cae 1874 void pre_exec() override;
f67539c2 1875 void execute(optional_yield y) override;
20effc67 1876 bool check_previously_completed(const RGWMultiCompleteUpload* parts);
3efd9988 1877 void complete() override;
7c673cae 1878
f67539c2 1879 virtual int get_params(optional_yield y) = 0;
7c673cae 1880 void send_response() override = 0;
11fdf7f2 1881 const char* name() const override { return "complete_multipart"; }
7c673cae
FG
1882 RGWOpType get_type() override { return RGW_OP_COMPLETE_MULTIPART; }
1883 uint32_t op_mask() override { return RGW_OP_TYPE_WRITE; }
1884};
1885
1886class RGWAbortMultipart : public RGWOp {
20effc67
TL
1887protected:
1888 jspan multipart_trace;
7c673cae
FG
1889public:
1890 RGWAbortMultipart() {}
1891
f67539c2 1892 int verify_permission(optional_yield y) override;
7c673cae 1893 void pre_exec() override;
f67539c2 1894 void execute(optional_yield y) override;
7c673cae
FG
1895
1896 void send_response() override = 0;
11fdf7f2 1897 const char* name() const override { return "abort_multipart"; }
7c673cae
FG
1898 RGWOpType get_type() override { return RGW_OP_ABORT_MULTIPART; }
1899 uint32_t op_mask() override { return RGW_OP_TYPE_DELETE; }
1900};
1901
1902class RGWListMultipart : public RGWOp {
1903protected:
20effc67
TL
1904 std::string upload_id;
1905 std::unique_ptr<rgw::sal::MultipartUpload> upload;
7c673cae
FG
1906 int max_parts;
1907 int marker;
1908 RGWAccessControlPolicy policy;
1909 bool truncated;
20effc67 1910 rgw_placement_rule* placement;
7c673cae
FG
1911
1912public:
1913 RGWListMultipart() {
1914 max_parts = 1000;
1915 marker = 0;
1916 truncated = false;
1917 }
1918
20effc67 1919 void init(rgw::sal::Store* store, struct req_state *s, RGWHandler *h) override {
7c673cae
FG
1920 RGWOp::init(store, s, h);
1921 policy = RGWAccessControlPolicy(s->cct);
1922 }
f67539c2 1923 int verify_permission(optional_yield y) override;
7c673cae 1924 void pre_exec() override;
f67539c2 1925 void execute(optional_yield y) override;
7c673cae 1926
f67539c2 1927 virtual int get_params(optional_yield y) = 0;
7c673cae 1928 void send_response() override = 0;
11fdf7f2 1929 const char* name() const override { return "list_multipart"; }
7c673cae
FG
1930 RGWOpType get_type() override { return RGW_OP_LIST_MULTIPART; }
1931 uint32_t op_mask() override { return RGW_OP_TYPE_READ; }
1932};
1933
7c673cae
FG
1934class RGWListBucketMultiparts : public RGWOp {
1935protected:
20effc67
TL
1936 std::string prefix;
1937 std::string marker_meta;
1938 std::string marker_key;
1939 std::string marker_upload_id;
1940 std::string next_marker_key;
1941 std::string next_marker_upload_id;
7c673cae 1942 int max_uploads;
20effc67
TL
1943 std::string delimiter;
1944 std::vector<std::unique_ptr<rgw::sal::MultipartUpload>> uploads;
1945 std::map<std::string, bool> common_prefixes;
7c673cae
FG
1946 bool is_truncated;
1947 int default_max;
9f95a23c 1948 bool encode_url {false};
7c673cae
FG
1949
1950public:
1951 RGWListBucketMultiparts() {
1952 max_uploads = 0;
1953 is_truncated = false;
1954 default_max = 0;
1955 }
1956
20effc67 1957 void init(rgw::sal::Store* store, struct req_state *s, RGWHandler *h) override {
7c673cae
FG
1958 RGWOp::init(store, s, h);
1959 max_uploads = default_max;
1960 }
1961
f67539c2 1962 int verify_permission(optional_yield y) override;
7c673cae 1963 void pre_exec() override;
f67539c2 1964 void execute(optional_yield y) override;
7c673cae 1965
f67539c2 1966 virtual int get_params(optional_yield y) = 0;
7c673cae 1967 void send_response() override = 0;
11fdf7f2 1968 const char* name() const override { return "list_bucket_multiparts"; }
7c673cae
FG
1969 RGWOpType get_type() override { return RGW_OP_LIST_BUCKET_MULTIPARTS; }
1970 uint32_t op_mask() override { return RGW_OP_TYPE_READ; }
1971};
1972
1973
1974class RGWGetCrossDomainPolicy : public RGWOp {
1975public:
1976 RGWGetCrossDomainPolicy() = default;
1977 ~RGWGetCrossDomainPolicy() override = default;
1978
f67539c2 1979 int verify_permission(optional_yield) override {
7c673cae
FG
1980 return 0;
1981 }
1982
f67539c2 1983 void execute(optional_yield) override {
7c673cae
FG
1984 op_ret = 0;
1985 }
1986
11fdf7f2 1987 const char* name() const override { return "get_crossdomain_policy"; }
7c673cae
FG
1988
1989 RGWOpType get_type() override {
1990 return RGW_OP_GET_CROSS_DOMAIN_POLICY;
1991 }
1992
1993 uint32_t op_mask() override {
1994 return RGW_OP_TYPE_READ;
1995 }
1996};
1997
1998
1999class RGWGetHealthCheck : public RGWOp {
2000public:
2001 RGWGetHealthCheck() = default;
2002 ~RGWGetHealthCheck() override = default;
2003
f67539c2 2004 int verify_permission(optional_yield) override {
7c673cae
FG
2005 return 0;
2006 }
2007
f67539c2 2008 void execute(optional_yield y) override;
7c673cae 2009
11fdf7f2 2010 const char* name() const override { return "get_health_check"; }
7c673cae
FG
2011
2012 RGWOpType get_type() override {
2013 return RGW_OP_GET_HEALTH_CHECK;
2014 }
2015
2016 uint32_t op_mask() override {
2017 return RGW_OP_TYPE_READ;
2018 }
2019};
2020
2021
2022class RGWDeleteMultiObj : public RGWOp {
2023protected:
11fdf7f2 2024 bufferlist data;
20effc67 2025 rgw::sal::Bucket* bucket;
7c673cae
FG
2026 bool quiet;
2027 bool status_dumped;
31f18b77 2028 bool acl_allowed = false;
f67539c2
TL
2029 bool bypass_perm;
2030 bool bypass_governance_mode;
2031
7c673cae
FG
2032
2033public:
2034 RGWDeleteMultiObj() {
7c673cae
FG
2035 quiet = false;
2036 status_dumped = false;
f67539c2
TL
2037 bypass_perm = true;
2038 bypass_governance_mode = false;
7c673cae 2039 }
f67539c2 2040 int verify_permission(optional_yield y) override;
7c673cae 2041 void pre_exec() override;
f67539c2 2042 void execute(optional_yield y) override;
7c673cae 2043
f67539c2 2044 virtual int get_params(optional_yield y) = 0;
7c673cae
FG
2045 virtual void send_status() = 0;
2046 virtual void begin_response() = 0;
2047 virtual void send_partial_response(rgw_obj_key& key, bool delete_marker,
20effc67 2048 const std::string& marker_version_id, int ret) = 0;
7c673cae 2049 virtual void end_response() = 0;
11fdf7f2 2050 const char* name() const override { return "multi_object_delete"; }
7c673cae
FG
2051 RGWOpType get_type() override { return RGW_OP_DELETE_MULTI_OBJ; }
2052 uint32_t op_mask() override { return RGW_OP_TYPE_DELETE; }
2053};
2054
2055class RGWInfo: public RGWOp {
2056public:
2057 RGWInfo() = default;
2058 ~RGWInfo() override = default;
2059
f67539c2 2060 int verify_permission(optional_yield) override { return 0; }
11fdf7f2 2061 const char* name() const override { return "get info"; }
7c673cae
FG
2062 RGWOpType get_type() override { return RGW_OP_GET_INFO; }
2063 uint32_t op_mask() override { return RGW_OP_TYPE_READ; }
2064};
2065
20effc67
TL
2066extern int rgw_build_bucket_policies(const DoutPrefixProvider *dpp, rgw::sal::Store* store,
2067 struct req_state* s, optional_yield y);
2068extern int rgw_build_object_policies(const DoutPrefixProvider *dpp, rgw::sal::Store* store,
2069 struct req_state *s, bool prefetch_data, optional_yield y);
2070extern void rgw_build_iam_environment(rgw::sal::Store* store,
2071 struct req_state* s);
2072extern std::vector<rgw::IAM::Policy> get_iam_user_policy_from_attr(CephContext* cct,
2073 std::map<std::string, bufferlist>& attrs,
2074 const std::string& tenant);
7c673cae 2075
f67539c2
TL
2076inline int get_system_versioning_params(req_state *s,
2077 uint64_t *olh_epoch,
20effc67 2078 std::string *version_id)
7c673cae
FG
2079{
2080 if (!s->system_request) {
2081 return 0;
2082 }
2083
2084 if (olh_epoch) {
20effc67 2085 std::string epoch_str = s->info.args.get(RGW_SYS_PARAM_PREFIX "versioned-epoch");
7c673cae 2086 if (!epoch_str.empty()) {
20effc67 2087 std::string err;
7c673cae
FG
2088 *olh_epoch = strict_strtol(epoch_str.c_str(), 10, &err);
2089 if (!err.empty()) {
b3b6e05e 2090 ldpp_subdout(s, rgw, 0) << "failed to parse versioned-epoch param"
7c673cae
FG
2091 << dendl;
2092 return -EINVAL;
2093 }
2094 }
2095 }
2096
2097 if (version_id) {
2098 *version_id = s->info.args.get(RGW_SYS_PARAM_PREFIX "version-id");
2099 }
2100
2101 return 0;
2102} /* get_system_versioning_params */
2103
2104static inline void format_xattr(std::string &xattr)
2105{
2106 /* If the extended attribute is not valid UTF-8, we encode it using
2107 * quoted-printable encoding.
2108 */
2109 if ((check_utf8(xattr.c_str(), xattr.length()) != 0) ||
2110 (check_for_control_characters(xattr.c_str(), xattr.length()) != 0)) {
2111 static const char MIME_PREFIX_STR[] = "=?UTF-8?Q?";
2112 static const int MIME_PREFIX_LEN = sizeof(MIME_PREFIX_STR) - 1;
2113 static const char MIME_SUFFIX_STR[] = "?=";
2114 static const int MIME_SUFFIX_LEN = sizeof(MIME_SUFFIX_STR) - 1;
2115 int mlen = mime_encode_as_qp(xattr.c_str(), NULL, 0);
2116 char *mime = new char[MIME_PREFIX_LEN + mlen + MIME_SUFFIX_LEN + 1];
2117 strcpy(mime, MIME_PREFIX_STR);
2118 mime_encode_as_qp(xattr.c_str(), mime + MIME_PREFIX_LEN, mlen);
2119 strcpy(mime + MIME_PREFIX_LEN + (mlen - 1), MIME_SUFFIX_STR);
2120 xattr.assign(mime);
2121 delete [] mime;
2122 }
2123} /* format_xattr */
2124
2125/**
2126 * Get the HTTP request metadata out of the req_state as a
2127 * map(<attr_name, attr_contents>, where attr_name is RGW_ATTR_PREFIX.HTTP_NAME)
2128 * s: The request state
2129 * attrs: will be filled up with attrs mapped as <attr_name, attr_contents>
3efd9988
FG
2130 * On success returns 0.
2131 * On failure returns a negative error code.
7c673cae
FG
2132 *
2133 */
b3b6e05e
TL
2134inline int rgw_get_request_metadata(const DoutPrefixProvider *dpp,
2135 CephContext* const cct,
f67539c2
TL
2136 struct req_info& info,
2137 std::map<std::string, ceph::bufferlist>& attrs,
2138 const bool allow_empty_attrs = true)
7c673cae 2139{
f67539c2 2140 static const std::set<std::string> blocklisted_headers = {
7c673cae
FG
2141 "x-amz-server-side-encryption-customer-algorithm",
2142 "x-amz-server-side-encryption-customer-key",
11fdf7f2
TL
2143 "x-amz-server-side-encryption-customer-key-md5",
2144 "x-amz-storage-class"
7c673cae 2145 };
3efd9988
FG
2146
2147 size_t valid_meta_count = 0;
2148 for (auto& kv : info.x_meta_map) {
2149 const std::string& name = kv.first;
2150 std::string& xattr = kv.second;
2151
f67539c2 2152 if (blocklisted_headers.count(name) == 1) {
b3b6e05e 2153 ldpp_subdout(dpp, rgw, 10) << "skipping x>> " << name << dendl;
7c673cae 2154 continue;
3efd9988 2155 } else if (allow_empty_attrs || !xattr.empty()) {
b3b6e05e 2156 ldpp_subdout(dpp, rgw, 10) << "x>> " << name << ":" << xattr << dendl;
7c673cae 2157 format_xattr(xattr);
3efd9988
FG
2158
2159 std::string attr_name(RGW_ATTR_PREFIX);
7c673cae 2160 attr_name.append(name);
3efd9988
FG
2161
2162 /* Check roughly whether we aren't going behind the limit on attribute
2163 * name. Passing here doesn't guarantee that an OSD will accept that
2164 * as ObjectStore::get_max_attr_name_length() can set the limit even
2165 * lower than the "osd_max_attr_name_len" configurable. */
eafe8130 2166 const auto max_attr_name_len = cct->_conf->rgw_max_attr_name_len;
3efd9988
FG
2167 if (max_attr_name_len && attr_name.length() > max_attr_name_len) {
2168 return -ENAMETOOLONG;
2169 }
2170
2171 /* Similar remarks apply to the check for value size. We're veryfing
2172 * it early at the RGW's side as it's being claimed in /info. */
eafe8130 2173 const auto max_attr_size = cct->_conf->rgw_max_attr_size;
3efd9988
FG
2174 if (max_attr_size && xattr.length() > max_attr_size) {
2175 return -EFBIG;
2176 }
2177
2178 /* Swift allows administrators to limit the number of metadats items
2179 * send _in a single request_. */
eafe8130
TL
2180 const auto max_attrs_num_in_req = cct->_conf->rgw_max_attrs_num_in_req;
2181 if (max_attrs_num_in_req &&
2182 ++valid_meta_count > max_attrs_num_in_req) {
3efd9988
FG
2183 return -E2BIG;
2184 }
2185
2186 auto rval = attrs.emplace(std::move(attr_name), ceph::bufferlist());
2187 /* At the moment the value of the freshly created attribute key-value
2188 * pair is an empty bufferlist. */
2189
2190 ceph::bufferlist& bl = rval.first->second;
7c673cae
FG
2191 bl.append(xattr.c_str(), xattr.size() + 1);
2192 }
2193 }
3efd9988
FG
2194
2195 return 0;
7c673cae
FG
2196} /* rgw_get_request_metadata */
2197
f67539c2 2198inline void encode_delete_at_attr(boost::optional<ceph::real_time> delete_at,
20effc67 2199 std::map<std::string, bufferlist>& attrs)
7c673cae
FG
2200{
2201 if (delete_at == boost::none) {
2202 return;
2203 }
2204
2205 bufferlist delatbl;
11fdf7f2 2206 encode(*delete_at, delatbl);
7c673cae
FG
2207 attrs[RGW_ATTR_DELETE_AT] = delatbl;
2208} /* encode_delete_at_attr */
2209
20effc67 2210inline void encode_obj_tags_attr(RGWObjTags* obj_tags, std::map<std::string, bufferlist>& attrs)
224ce89b
WB
2211{
2212 if (obj_tags == nullptr){
2213 // we assume the user submitted a tag format which we couldn't parse since
2214 // this wouldn't be parsed later by get/put obj tags, lets delete if the
2215 // attr was populated
2216 return;
2217 }
2218
2219 bufferlist tagsbl;
2220 obj_tags->encode(tagsbl);
2221 attrs[RGW_ATTR_TAGS] = tagsbl;
2222}
2223
f67539c2 2224inline int encode_dlo_manifest_attr(const char * const dlo_manifest,
20effc67 2225 std::map<std::string, bufferlist>& attrs)
7c673cae 2226{
20effc67 2227 std::string dm = dlo_manifest;
7c673cae 2228
20effc67 2229 if (dm.find('/') == std::string::npos) {
7c673cae
FG
2230 return -EINVAL;
2231 }
2232
2233 bufferlist manifest_bl;
2234 manifest_bl.append(dlo_manifest, strlen(dlo_manifest) + 1);
2235 attrs[RGW_ATTR_USER_MANIFEST] = manifest_bl;
2236
2237 return 0;
2238} /* encode_dlo_manifest_attr */
2239
20effc67 2240inline void complete_etag(MD5& hash, std::string *etag)
7c673cae
FG
2241{
2242 char etag_buf[CEPH_CRYPTO_MD5_DIGESTSIZE];
2243 char etag_buf_str[CEPH_CRYPTO_MD5_DIGESTSIZE * 2 + 16];
2244
11fdf7f2 2245 hash.Final((unsigned char *)etag_buf);
7c673cae
FG
2246 buf_to_hex((const unsigned char *)etag_buf, CEPH_CRYPTO_MD5_DIGESTSIZE,
2247 etag_buf_str);
2248
2249 *etag = etag_buf_str;
2250} /* complete_etag */
2251
f67539c2
TL
2252using boost::container::flat_map;
2253
2254class RGWGetAttrs : public RGWOp {
2255public:
2256 using get_attrs_t = flat_map<std::string, std::optional<buffer::list>>;
2257protected:
2258 get_attrs_t attrs;
2259
2260public:
2261 RGWGetAttrs()
2262 {}
2263
2264 virtual ~RGWGetAttrs() {}
2265
2266 void emplace_key(std::string&& key) {
2267 attrs.emplace(std::move(key), std::nullopt);
2268 }
2269
2270 int verify_permission(optional_yield y);
2271 void pre_exec();
2272 void execute(optional_yield y);
2273
2274 virtual int get_params() = 0;
2275 virtual void send_response() = 0;
2276 virtual const char* name() const { return "get_attrs"; }
2277 virtual RGWOpType get_type() { return RGW_OP_GET_ATTRS; }
2278 virtual uint32_t op_mask() { return RGW_OP_TYPE_READ; }
2279}; /* RGWGetAttrs */
2280
7c673cae
FG
2281class RGWSetAttrs : public RGWOp {
2282protected:
20effc67 2283 std::map<std::string, buffer::list> attrs;
7c673cae
FG
2284
2285public:
2286 RGWSetAttrs() {}
2287 ~RGWSetAttrs() override {}
2288
2289 void emplace_attr(std::string&& key, buffer::list&& bl) {
2290 attrs.emplace(std::move(key), std::move(bl));
2291 }
2292
f67539c2 2293 int verify_permission(optional_yield y) override;
7c673cae 2294 void pre_exec() override;
f67539c2 2295 void execute(optional_yield y) override;
7c673cae 2296
f67539c2 2297 virtual int get_params(optional_yield y) = 0;
7c673cae 2298 void send_response() override = 0;
11fdf7f2 2299 const char* name() const override { return "set_attrs"; }
7c673cae
FG
2300 RGWOpType get_type() override { return RGW_OP_SET_ATTRS; }
2301 uint32_t op_mask() override { return RGW_OP_TYPE_WRITE; }
2302};
2303
f67539c2
TL
2304class RGWRMAttrs : public RGWOp {
2305protected:
20effc67 2306 rgw::sal::Attrs attrs;
f67539c2
TL
2307
2308public:
2309 RGWRMAttrs()
2310 {}
2311
2312 virtual ~RGWRMAttrs() {}
2313
2314 void emplace_key(std::string&& key) {
2315 attrs.emplace(std::move(key), buffer::list());
2316 }
2317
2318 int verify_permission(optional_yield y);
2319 void pre_exec();
2320 void execute(optional_yield y);
2321
2322 virtual int get_params() = 0;
2323 virtual void send_response() = 0;
2324 virtual const char* name() const { return "rm_attrs"; }
2325 virtual RGWOpType get_type() { return RGW_OP_DELETE_ATTRS; }
2326 virtual uint32_t op_mask() { return RGW_OP_TYPE_DELETE; }
2327}; /* RGWRMAttrs */
2328
7c673cae 2329class RGWGetObjLayout : public RGWOp {
7c673cae
FG
2330public:
2331 RGWGetObjLayout() {
2332 }
2333
2334 int check_caps(RGWUserCaps& caps) {
2335 return caps.check_cap("admin", RGW_CAP_READ);
2336 }
f67539c2 2337 int verify_permission(optional_yield) override {
9f95a23c 2338 return check_caps(s->user->get_info().caps);
7c673cae 2339 }
11fdf7f2 2340 void pre_exec() override;
f67539c2 2341 void execute(optional_yield y) override;
7c673cae 2342
11fdf7f2
TL
2343 const char* name() const override { return "get_obj_layout"; }
2344 virtual RGWOpType get_type() override { return RGW_OP_GET_OBJ_LAYOUT; }
2345 virtual uint32_t op_mask() override { return RGW_OP_TYPE_READ; }
7c673cae
FG
2346};
2347
31f18b77 2348class RGWPutBucketPolicy : public RGWOp {
11fdf7f2 2349 bufferlist data;
31f18b77
FG
2350public:
2351 RGWPutBucketPolicy() = default;
2352 ~RGWPutBucketPolicy() {
31f18b77
FG
2353 }
2354 void send_response() override;
f67539c2 2355 int verify_permission(optional_yield y) override;
31f18b77
FG
2356 uint32_t op_mask() override {
2357 return RGW_OP_TYPE_WRITE;
2358 }
f67539c2
TL
2359 void execute(optional_yield y) override;
2360 int get_params(optional_yield y);
11fdf7f2 2361 const char* name() const override { return "put_bucket_policy"; }
31f18b77
FG
2362 RGWOpType get_type() override {
2363 return RGW_OP_PUT_BUCKET_POLICY;
2364 }
2365};
7c673cae 2366
31f18b77
FG
2367class RGWGetBucketPolicy : public RGWOp {
2368 buffer::list policy;
2369public:
2370 RGWGetBucketPolicy() = default;
2371 void send_response() override;
f67539c2 2372 int verify_permission(optional_yield y) override;
31f18b77
FG
2373 uint32_t op_mask() override {
2374 return RGW_OP_TYPE_READ;
2375 }
f67539c2 2376 void execute(optional_yield y) override;
11fdf7f2 2377 const char* name() const override { return "get_bucket_policy"; }
31f18b77
FG
2378 RGWOpType get_type() override {
2379 return RGW_OP_GET_BUCKET_POLICY;
2380 }
2381};
2382
2383class RGWDeleteBucketPolicy : public RGWOp {
2384public:
2385 RGWDeleteBucketPolicy() = default;
2386 void send_response() override;
f67539c2 2387 int verify_permission(optional_yield y) override;
31f18b77
FG
2388 uint32_t op_mask() override {
2389 return RGW_OP_TYPE_WRITE;
2390 }
f67539c2
TL
2391 void execute(optional_yield y) override;
2392 int get_params(optional_yield y);
11fdf7f2 2393 const char* name() const override { return "delete_bucket_policy"; }
31f18b77
FG
2394 RGWOpType get_type() override {
2395 return RGW_OP_DELETE_BUCKET_POLICY;
2396 }
2397};
2398
eafe8130
TL
2399class RGWPutBucketObjectLock : public RGWOp {
2400protected:
2401 bufferlist data;
2402 bufferlist obj_lock_bl;
2403 RGWObjectLock obj_lock;
2404public:
2405 RGWPutBucketObjectLock() = default;
2406 ~RGWPutBucketObjectLock() {}
f67539c2 2407 int verify_permission(optional_yield y) override;
eafe8130 2408 void pre_exec() override;
f67539c2
TL
2409 void execute(optional_yield y) override;
2410 virtual void send_response() override = 0;
2411 virtual int get_params(optional_yield y) = 0;
eafe8130
TL
2412 const char* name() const override { return "put_bucket_object_lock"; }
2413 RGWOpType get_type() override { return RGW_OP_PUT_BUCKET_OBJ_LOCK; }
2414 uint32_t op_mask() override { return RGW_OP_TYPE_WRITE; }
2415};
2416
2417class RGWGetBucketObjectLock : public RGWOp {
2418public:
f67539c2 2419 int verify_permission(optional_yield y) override;
eafe8130 2420 void pre_exec() override;
f67539c2
TL
2421 void execute(optional_yield y) override;
2422 virtual void send_response() override = 0;
eafe8130
TL
2423 const char* name() const override {return "get_bucket_object_lock"; }
2424 RGWOpType get_type() override { return RGW_OP_GET_BUCKET_OBJ_LOCK; }
2425 uint32_t op_mask() override { return RGW_OP_TYPE_READ; }
2426};
2427
2428class RGWPutObjRetention : public RGWOp {
2429protected:
2430 bufferlist data;
2431 RGWObjectRetention obj_retention;
2432 bool bypass_perm;
2433 bool bypass_governance_mode;
2434public:
2435 RGWPutObjRetention():bypass_perm(true), bypass_governance_mode(false) {}
f67539c2 2436 int verify_permission(optional_yield y) override;
eafe8130 2437 void pre_exec() override;
f67539c2 2438 void execute(optional_yield y) override;
eafe8130 2439 virtual void send_response() override = 0;
f67539c2 2440 virtual int get_params(optional_yield y) = 0;
eafe8130
TL
2441 const char* name() const override { return "put_obj_retention"; }
2442 uint32_t op_mask() override { return RGW_OP_TYPE_WRITE; }
2443 RGWOpType get_type() override { return RGW_OP_PUT_OBJ_RETENTION; }
2444};
2445
2446class RGWGetObjRetention : public RGWOp {
2447protected:
2448 RGWObjectRetention obj_retention;
2449public:
f67539c2 2450 int verify_permission(optional_yield y) override;
eafe8130 2451 void pre_exec() override;
f67539c2
TL
2452 void execute(optional_yield y) override;
2453 virtual void send_response() override = 0;
eafe8130
TL
2454 const char* name() const override {return "get_obj_retention"; }
2455 RGWOpType get_type() override { return RGW_OP_GET_OBJ_RETENTION; }
2456 uint32_t op_mask() override { return RGW_OP_TYPE_READ; }
2457};
2458
2459class RGWPutObjLegalHold : public RGWOp {
2460protected:
2461 bufferlist data;
2462 RGWObjectLegalHold obj_legal_hold;
2463public:
f67539c2 2464 int verify_permission(optional_yield y) override;
eafe8130 2465 void pre_exec() override;
f67539c2 2466 void execute(optional_yield y) override;
eafe8130 2467 virtual void send_response() override = 0;
f67539c2 2468 virtual int get_params(optional_yield y) = 0;
eafe8130
TL
2469 const char* name() const override { return "put_obj_legal_hold"; }
2470 uint32_t op_mask() override { return RGW_OP_TYPE_WRITE; }
2471 RGWOpType get_type() override { return RGW_OP_PUT_OBJ_LEGAL_HOLD; }
2472};
2473
2474class RGWGetObjLegalHold : public RGWOp {
2475protected:
2476 RGWObjectLegalHold obj_legal_hold;
2477public:
f67539c2 2478 int verify_permission(optional_yield y) override;
eafe8130 2479 void pre_exec() override;
f67539c2
TL
2480 void execute(optional_yield y) override;
2481 virtual void send_response() override = 0;
eafe8130
TL
2482 const char* name() const override {return "get_obj_legal_hold"; }
2483 RGWOpType get_type() override { return RGW_OP_GET_OBJ_LEGAL_HOLD; }
2484 uint32_t op_mask() override { return RGW_OP_TYPE_READ; }
2485};
2486
31f18b77
FG
2487
2488class RGWConfigBucketMetaSearch : public RGWOp {
2489protected:
2490 std::map<std::string, uint32_t> mdsearch_config;
2491public:
2492 RGWConfigBucketMetaSearch() {}
2493
f67539c2 2494 int verify_permission(optional_yield y) override;
11fdf7f2 2495 void pre_exec() override;
f67539c2 2496 void execute(optional_yield y) override;
31f18b77 2497
f67539c2 2498 virtual int get_params(optional_yield y) = 0;
11fdf7f2
TL
2499 const char* name() const override { return "config_bucket_meta_search"; }
2500 virtual RGWOpType get_type() override { return RGW_OP_CONFIG_BUCKET_META_SEARCH; }
2501 virtual uint32_t op_mask() override { return RGW_OP_TYPE_WRITE; }
31f18b77
FG
2502};
2503
2504class RGWGetBucketMetaSearch : public RGWOp {
2505public:
2506 RGWGetBucketMetaSearch() {}
2507
f67539c2 2508 int verify_permission(optional_yield y) override;
11fdf7f2 2509 void pre_exec() override;
f67539c2 2510 void execute(optional_yield) override {}
31f18b77 2511
11fdf7f2
TL
2512 const char* name() const override { return "get_bucket_meta_search"; }
2513 virtual RGWOpType get_type() override { return RGW_OP_GET_BUCKET_META_SEARCH; }
2514 virtual uint32_t op_mask() override { return RGW_OP_TYPE_READ; }
31f18b77
FG
2515};
2516
2517class RGWDelBucketMetaSearch : public RGWOp {
2518public:
2519 RGWDelBucketMetaSearch() {}
2520
f67539c2 2521 int verify_permission(optional_yield y) override;
11fdf7f2 2522 void pre_exec() override;
f67539c2 2523 void execute(optional_yield y) override;
31f18b77 2524
11fdf7f2 2525 const char* name() const override { return "delete_bucket_meta_search"; }
31f18b77 2526 virtual RGWOpType delete_type() { return RGW_OP_DEL_BUCKET_META_SEARCH; }
11fdf7f2 2527 virtual uint32_t op_mask() override { return RGW_OP_TYPE_WRITE; }
31f18b77 2528};
7c673cae 2529
28e407b8
AA
2530class RGWGetClusterStat : public RGWOp {
2531protected:
f67539c2 2532 RGWClusterStat stats_op;
28e407b8
AA
2533public:
2534 RGWGetClusterStat() {}
2535
20effc67 2536 void init(rgw::sal::Store* store, struct req_state *s, RGWHandler *h) override {
28e407b8
AA
2537 RGWOp::init(store, s, h);
2538 }
f67539c2 2539 int verify_permission(optional_yield) override {return 0;}
11fdf7f2 2540 virtual void send_response() override = 0;
f67539c2
TL
2541 virtual int get_params(optional_yield y) = 0;
2542 void execute(optional_yield y) override;
11fdf7f2
TL
2543 const char* name() const override { return "get_cluster_stat"; }
2544 dmc::client_id dmclock_client() override { return dmc::client_id::admin; }
28e407b8
AA
2545};
2546
9f95a23c
TL
2547class RGWGetBucketPolicyStatus : public RGWOp {
2548protected:
2549 bool isPublic {false};
2550public:
f67539c2 2551 int verify_permission(optional_yield y) override;
9f95a23c
TL
2552 const char* name() const override { return "get_bucket_policy_status"; }
2553 virtual RGWOpType get_type() override { return RGW_OP_GET_BUCKET_POLICY_STATUS; }
2554 virtual uint32_t op_mask() override { return RGW_OP_TYPE_READ; }
f67539c2 2555 void execute(optional_yield y) override;
9f95a23c
TL
2556 dmc::client_id dmclock_client() override { return dmc::client_id::metadata; }
2557};
2558
2559class RGWPutBucketPublicAccessBlock : public RGWOp {
2560protected:
2561 bufferlist data;
2562 PublicAccessBlockConfiguration access_conf;
2563public:
f67539c2 2564 int verify_permission(optional_yield y) override;
9f95a23c
TL
2565 const char* name() const override { return "put_bucket_public_access_block";}
2566 virtual RGWOpType get_type() override { return RGW_OP_PUT_BUCKET_PUBLIC_ACCESS_BLOCK; }
2567 virtual uint32_t op_mask() override { return RGW_OP_TYPE_WRITE; }
f67539c2
TL
2568 int get_params(optional_yield y);
2569 void execute(optional_yield y) override;
9f95a23c
TL
2570 dmc::client_id dmclock_client() override { return dmc::client_id::metadata; }
2571};
2572
2573class RGWGetBucketPublicAccessBlock : public RGWOp {
2574protected:
2575 PublicAccessBlockConfiguration access_conf;
2576public:
f67539c2 2577 int verify_permission(optional_yield y) override;
9f95a23c
TL
2578 const char* name() const override { return "get_bucket_public_access_block";}
2579 virtual RGWOpType get_type() override { return RGW_OP_GET_BUCKET_PUBLIC_ACCESS_BLOCK; }
2580 virtual uint32_t op_mask() override { return RGW_OP_TYPE_READ; }
f67539c2
TL
2581 int get_params(optional_yield y);
2582 void execute(optional_yield y) override;
9f95a23c
TL
2583 dmc::client_id dmclock_client() override { return dmc::client_id::metadata; }
2584};
2585
2586class RGWDeleteBucketPublicAccessBlock : public RGWOp {
2587protected:
2588 PublicAccessBlockConfiguration access_conf;
2589public:
f67539c2 2590 int verify_permission(optional_yield y) override;
9f95a23c
TL
2591 const char* name() const override { return "delete_bucket_public_access_block";}
2592 virtual RGWOpType get_type() override { return RGW_OP_DELETE_BUCKET_PUBLIC_ACCESS_BLOCK; }
2593 virtual uint32_t op_mask() override { return RGW_OP_TYPE_WRITE; }
f67539c2
TL
2594 int get_params(optional_yield y);
2595 void execute(optional_yield y) override;
9f95a23c
TL
2596 void send_response() override;
2597 dmc::client_id dmclock_client() override { return dmc::client_id::metadata; }
2598};
2599
f67539c2 2600inline int parse_value_and_bound(
20effc67 2601 const std::string &input,
f64942e4
AA
2602 int &output,
2603 const long lower_bound,
2604 const long upper_bound,
2605 const long default_val)
2606{
2607 if (!input.empty()) {
2608 char *endptr;
2609 output = strtol(input.c_str(), &endptr, 10);
2610 if (endptr) {
2611 if (endptr == input.c_str()) return -EINVAL;
2612 while (*endptr && isspace(*endptr)) // ignore white space
2613 endptr++;
2614 if (*endptr) {
2615 return -EINVAL;
2616 }
2617 }
2618 if(output > upper_bound) {
2619 output = upper_bound;
2620 }
2621 if(output < lower_bound) {
2622 output = lower_bound;
2623 }
2624 } else {
2625 output = default_val;
2626 }
2627
2628 return 0;
2629}
28e407b8 2630
7c673cae 2631#endif /* CEPH_RGW_OP_H */