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