1 // -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
2 // vim: ts=8 sw=2 smarttab
4 * Ceph - scalable distributed file system
6 * Copyright (C) 2004-2009 Sage Weil <sage@newdream.net>
7 * Copyright (C) 2015 Yehuda Sadeh <yehuda@redhat.com>
9 * This is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU Lesser General Public
11 * License version 2.1, as published by the Free Software
12 * Foundation. See file COPYING.
16 #ifndef CEPH_RGW_COMMON_H
17 #define CEPH_RGW_COMMON_H
21 #include <boost/utility/string_view.hpp>
23 #include "common/ceph_crypto.h"
24 #include "common/perf_counters.h"
28 #include "rgw_iam_policy.h"
29 #include "rgw_quota.h"
30 #include "rgw_string.h"
31 #include "rgw_website.h"
32 #include "cls/version/cls_version_types.h"
33 #include "cls/user/cls_user_types.h"
34 #include "cls/rgw/cls_rgw_types.h"
35 #include "include/rados/librados.hpp"
41 using ceph::crypto::MD5
;
44 #define RGW_ATTR_PREFIX "user.rgw."
46 #define RGW_HTTP_RGWX_ATTR_PREFIX "RGWX_ATTR_"
47 #define RGW_HTTP_RGWX_ATTR_PREFIX_OUT "Rgwx-Attr-"
49 #define RGW_AMZ_PREFIX "x-amz-"
50 #define RGW_AMZ_META_PREFIX RGW_AMZ_PREFIX "meta-"
51 #define RGW_AMZ_WEBSITE_REDIRECT_LOCATION RGW_AMZ_PREFIX "website-redirect-location"
52 #define RGW_AMZ_TAG_COUNT RGW_AMZ_PREFIX "tagging-count"
54 #define RGW_SYS_PARAM_PREFIX "rgwx-"
56 #define RGW_ATTR_ACL RGW_ATTR_PREFIX "acl"
57 #define RGW_ATTR_LC RGW_ATTR_PREFIX "lc"
58 #define RGW_ATTR_CORS RGW_ATTR_PREFIX "cors"
59 #define RGW_ATTR_ETAG RGW_ATTR_PREFIX "etag"
60 #define RGW_ATTR_BUCKETS RGW_ATTR_PREFIX "buckets"
61 #define RGW_ATTR_META_PREFIX RGW_ATTR_PREFIX RGW_AMZ_META_PREFIX
62 #define RGW_ATTR_CONTENT_TYPE RGW_ATTR_PREFIX "content_type"
63 #define RGW_ATTR_CACHE_CONTROL RGW_ATTR_PREFIX "cache_control"
64 #define RGW_ATTR_CONTENT_DISP RGW_ATTR_PREFIX "content_disposition"
65 #define RGW_ATTR_CONTENT_ENC RGW_ATTR_PREFIX "content_encoding"
66 #define RGW_ATTR_CONTENT_LANG RGW_ATTR_PREFIX "content_language"
67 #define RGW_ATTR_EXPIRES RGW_ATTR_PREFIX "expires"
68 #define RGW_ATTR_DELETE_AT RGW_ATTR_PREFIX "delete_at"
69 #define RGW_ATTR_ID_TAG RGW_ATTR_PREFIX "idtag"
70 #define RGW_ATTR_SHADOW_OBJ RGW_ATTR_PREFIX "shadow_name"
71 #define RGW_ATTR_MANIFEST RGW_ATTR_PREFIX "manifest"
72 #define RGW_ATTR_USER_MANIFEST RGW_ATTR_PREFIX "user_manifest"
73 #define RGW_ATTR_AMZ_WEBSITE_REDIRECT_LOCATION RGW_ATTR_PREFIX RGW_AMZ_WEBSITE_REDIRECT_LOCATION
74 #define RGW_ATTR_SLO_MANIFEST RGW_ATTR_PREFIX "slo_manifest"
75 /* Information whether an object is SLO or not must be exposed to
76 * user through custom HTTP header named X-Static-Large-Object. */
77 #define RGW_ATTR_SLO_UINDICATOR RGW_ATTR_META_PREFIX "static-large-object"
78 #define RGW_ATTR_X_ROBOTS_TAG RGW_ATTR_PREFIX "x-robots-tag"
80 #define RGW_ATTR_PG_VER RGW_ATTR_PREFIX "pg_ver"
81 #define RGW_ATTR_SOURCE_ZONE RGW_ATTR_PREFIX "source_zone"
82 #define RGW_ATTR_TAGS RGW_ATTR_PREFIX RGW_AMZ_PREFIX "tagging"
84 #define RGW_ATTR_TEMPURL_KEY1 RGW_ATTR_META_PREFIX "temp-url-key"
85 #define RGW_ATTR_TEMPURL_KEY2 RGW_ATTR_META_PREFIX "temp-url-key-2"
87 /* Account/container quota of the Swift API. */
88 #define RGW_ATTR_QUOTA_NOBJS RGW_ATTR_META_PREFIX "quota-count"
89 #define RGW_ATTR_QUOTA_MSIZE RGW_ATTR_META_PREFIX "quota-bytes"
91 /* Static Web Site of Swift API. */
92 #define RGW_ATTR_WEB_INDEX RGW_ATTR_META_PREFIX "web-index"
93 #define RGW_ATTR_WEB_ERROR RGW_ATTR_META_PREFIX "web-error"
94 #define RGW_ATTR_WEB_LISTINGS RGW_ATTR_META_PREFIX "web-listings"
95 #define RGW_ATTR_WEB_LIST_CSS RGW_ATTR_META_PREFIX "web-listings-css"
96 #define RGW_ATTR_SUBDIR_MARKER RGW_ATTR_META_PREFIX "web-directory-type"
98 #define RGW_ATTR_OLH_PREFIX RGW_ATTR_PREFIX "olh."
100 #define RGW_ATTR_OLH_INFO RGW_ATTR_OLH_PREFIX "info"
101 #define RGW_ATTR_OLH_VER RGW_ATTR_OLH_PREFIX "ver"
102 #define RGW_ATTR_OLH_ID_TAG RGW_ATTR_OLH_PREFIX "idtag"
103 #define RGW_ATTR_OLH_PENDING_PREFIX RGW_ATTR_OLH_PREFIX "pending."
105 #define RGW_ATTR_COMPRESSION RGW_ATTR_PREFIX "compression"
108 #define RGW_ATTR_IAM_POLICY RGW_ATTR_PREFIX "iam-policy"
111 /* RGW File Attributes */
112 #define RGW_ATTR_UNIX_KEY1 RGW_ATTR_PREFIX "unix-key1"
113 #define RGW_ATTR_UNIX1 RGW_ATTR_PREFIX "unix1"
115 #define RGW_ATTR_CRYPT_PREFIX RGW_ATTR_PREFIX "crypt."
116 #define RGW_ATTR_CRYPT_MODE RGW_ATTR_CRYPT_PREFIX "mode"
117 #define RGW_ATTR_CRYPT_KEYMD5 RGW_ATTR_CRYPT_PREFIX "keymd5"
118 #define RGW_ATTR_CRYPT_KEYID RGW_ATTR_CRYPT_PREFIX "keyid"
119 #define RGW_ATTR_CRYPT_KEYSEL RGW_ATTR_CRYPT_PREFIX "keysel"
121 #define RGW_BUCKETS_OBJ_SUFFIX ".buckets"
123 #define RGW_FORMAT_PLAIN 0
124 #define RGW_FORMAT_XML 1
125 #define RGW_FORMAT_JSON 2
126 #define RGW_FORMAT_HTML 3
128 #define RGW_CAP_READ 0x1
129 #define RGW_CAP_WRITE 0x2
130 #define RGW_CAP_ALL (RGW_CAP_READ | RGW_CAP_WRITE)
132 #define RGW_REST_SWIFT 0x1
133 #define RGW_REST_SWIFT_AUTH 0x2
134 #define RGW_REST_S3 0x4
135 #define RGW_REST_WEBSITE 0x8
137 #define RGW_SUSPENDED_USER_AUID (uint64_t)-2
139 #define RGW_OP_TYPE_READ 0x01
140 #define RGW_OP_TYPE_WRITE 0x02
141 #define RGW_OP_TYPE_DELETE 0x04
143 #define RGW_OP_TYPE_MODIFY (RGW_OP_TYPE_WRITE | RGW_OP_TYPE_DELETE)
144 #define RGW_OP_TYPE_ALL (RGW_OP_TYPE_READ | RGW_OP_TYPE_WRITE | RGW_OP_TYPE_DELETE)
146 #define RGW_DEFAULT_MAX_BUCKETS 1000
148 #define RGW_DEFER_TO_BUCKET_ACLS_RECURSE 1
149 #define RGW_DEFER_TO_BUCKET_ACLS_FULL_CONTROL 2
151 #define STATUS_CREATED 1900
152 #define STATUS_ACCEPTED 1901
153 #define STATUS_NO_CONTENT 1902
154 #define STATUS_PARTIAL_CONTENT 1903
155 #define STATUS_REDIRECT 1904
156 #define STATUS_NO_APPLY 1905
157 #define STATUS_APPLIED 1906
159 #define ERR_INVALID_BUCKET_NAME 2000
160 #define ERR_INVALID_OBJECT_NAME 2001
161 #define ERR_NO_SUCH_BUCKET 2002
162 #define ERR_METHOD_NOT_ALLOWED 2003
163 #define ERR_INVALID_DIGEST 2004
164 #define ERR_BAD_DIGEST 2005
165 #define ERR_UNRESOLVABLE_EMAIL 2006
166 #define ERR_INVALID_PART 2007
167 #define ERR_INVALID_PART_ORDER 2008
168 #define ERR_NO_SUCH_UPLOAD 2009
169 #define ERR_REQUEST_TIMEOUT 2010
170 #define ERR_LENGTH_REQUIRED 2011
171 #define ERR_REQUEST_TIME_SKEWED 2012
172 #define ERR_BUCKET_EXISTS 2013
173 #define ERR_BAD_URL 2014
174 #define ERR_PRECONDITION_FAILED 2015
175 #define ERR_NOT_MODIFIED 2016
176 #define ERR_INVALID_UTF8 2017
177 #define ERR_UNPROCESSABLE_ENTITY 2018
178 #define ERR_TOO_LARGE 2019
179 #define ERR_TOO_MANY_BUCKETS 2020
180 #define ERR_INVALID_REQUEST 2021
181 #define ERR_TOO_SMALL 2022
182 #define ERR_NOT_FOUND 2023
183 #define ERR_PERMANENT_REDIRECT 2024
184 #define ERR_LOCKED 2025
185 #define ERR_QUOTA_EXCEEDED 2026
186 #define ERR_SIGNATURE_NO_MATCH 2027
187 #define ERR_INVALID_ACCESS_KEY 2028
188 #define ERR_MALFORMED_XML 2029
189 #define ERR_USER_EXIST 2030
190 #define ERR_NOT_SLO_MANIFEST 2031
191 #define ERR_EMAIL_EXIST 2032
192 #define ERR_KEY_EXIST 2033
193 #define ERR_INVALID_SECRET_KEY 2034
194 #define ERR_INVALID_KEY_TYPE 2035
195 #define ERR_INVALID_CAP 2036
196 #define ERR_INVALID_TENANT_NAME 2037
197 #define ERR_WEBSITE_REDIRECT 2038
198 #define ERR_NO_SUCH_WEBSITE_CONFIGURATION 2039
199 #define ERR_AMZ_CONTENT_SHA256_MISMATCH 2040
200 #define ERR_NO_SUCH_LC 2041
201 #define ERR_NO_SUCH_USER 2042
202 #define ERR_NO_SUCH_SUBUSER 2043
203 #define ERR_USER_SUSPENDED 2100
204 #define ERR_INTERNAL_ERROR 2200
205 #define ERR_NOT_IMPLEMENTED 2201
206 #define ERR_SERVICE_UNAVAILABLE 2202
207 #define ERR_ROLE_EXISTS 2203
208 #define ERR_MALFORMED_DOC 2204
209 #define ERR_NO_ROLE_FOUND 2205
210 #define ERR_DELETE_CONFLICT 2206
211 #define ERR_NO_SUCH_BUCKET_POLICY 2207
212 #define ERR_INVALID_LOCATION_CONSTRAINT 2208
213 #define ERR_TAG_CONFLICT 2209
214 #define ERR_INVALID_TAG 2210
215 #define ERR_ZERO_IN_URL 2211
217 #define ERR_BUSY_RESHARDING 2300
220 #define UINT32_MAX (0xffffffffu)
225 typedef void *RGWAccessHandle
;
230 extern PerfCounters
*perfcounter
;
232 extern int rgw_perf_start(CephContext
*cct
);
233 extern void rgw_perf_stop(CephContext
*cct
);
254 l_rgw_keystone_token_cache_hit
,
255 l_rgw_keystone_token_cache_miss
,
261 /* size should be the required string size + 1 */
262 extern int gen_rand_base64(CephContext
*cct
, char *dest
, int size
);
263 extern int gen_rand_alphanumeric(CephContext
*cct
, char *dest
, int size
);
264 extern int gen_rand_alphanumeric_lower(CephContext
*cct
, char *dest
, int size
);
265 extern int gen_rand_alphanumeric_upper(CephContext
*cct
, char *dest
, int size
);
266 extern int gen_rand_alphanumeric_no_underscore(CephContext
*cct
, char *dest
, int size
);
267 extern int gen_rand_alphanumeric_plain(CephContext
*cct
, char *dest
, int size
);
269 extern int gen_rand_alphanumeric_lower(CephContext
*cct
, string
*str
, int length
);
271 enum RGWIntentEvent
{
276 enum RGWObjCategory
{
277 RGW_OBJ_CATEGORY_NONE
= 0,
278 RGW_OBJ_CATEGORY_MAIN
= 1,
279 RGW_OBJ_CATEGORY_SHADOW
= 2,
280 RGW_OBJ_CATEGORY_MULTIMETA
= 3,
283 /** Store error returns for output at a different point in the program */
287 bool is_clear() const;
289 friend std::ostream
& operator<<(std::ostream
& oss
, const rgw_err
&err
);
293 std::string err_code
;
299 /* Helper class used for RGWHTTPArgs parsing */
306 explicit NameVal(string nv
) : str(nv
) {}
310 string
& get_name() { return name
; }
311 string
& get_val() { return val
; }
314 /** Stores the XML arguments associated with the HTTP request in req_state*/
317 string str
, empty_str
;
318 map
<string
, string
> val_map
;
319 map
<string
, string
> sys_val_map
;
320 map
<string
, string
> sub_resources
;
321 bool has_resp_modifier
;
322 bool admin_subresource_added
;
324 RGWHTTPArgs() : has_resp_modifier(false), admin_subresource_added(false) {}
326 /** Set the arguments; as received */
328 has_resp_modifier
= false;
330 sub_resources
.clear();
333 /** parse the received arguments */
335 void append(const string
& name
, const string
& val
);
336 /** Get the value for a specific argument parameter */
337 const string
& get(const string
& name
, bool *exists
= NULL
) const;
338 int get_bool(const string
& name
, bool *val
, bool *exists
);
339 int get_bool(const char *name
, bool *val
, bool *exists
);
340 void get_bool(const char *name
, bool *val
, bool def_val
);
342 /** Get the value for specific system argument parameter */
343 std::string
sys_get(const string
& name
, bool *exists
= nullptr) const;
345 /** see if a parameter is contained in this RGWHTTPArgs */
346 bool exists(const char *name
) const {
347 return (val_map
.find(name
) != std::end(val_map
));
349 bool sub_resource_exists(const char *name
) const {
350 return (sub_resources
.find(name
) != std::end(sub_resources
));
352 map
<string
, string
>& get_params() {
355 const std::map
<std::string
, std::string
>& get_sub_resources() const {
356 return sub_resources
;
358 unsigned get_num_params() const {
359 return val_map
.size();
361 bool has_response_modifier() const {
362 return has_resp_modifier
;
364 void set_system() { /* make all system params visible */
365 map
<string
, string
>::iterator iter
;
366 for (iter
= sys_val_map
.begin(); iter
!= sys_val_map
.end(); ++iter
) {
367 val_map
[iter
->first
] = iter
->second
;
370 const string
& get_str() {
375 const char *rgw_conf_get(const map
<string
, string
, ltstr_nocase
>& conf_map
, const char *name
, const char *def_val
);
376 int rgw_conf_get_int(const map
<string
, string
, ltstr_nocase
>& conf_map
, const char *name
, int def_val
);
377 bool rgw_conf_get_bool(const map
<string
, string
, ltstr_nocase
>& conf_map
, const char *name
, bool def_val
);
384 void init(CephContext
*cct
, RGWEnv
* env
);
389 defer_to_bucket_acls(0) {
393 int enable_usage_log
;
394 uint8_t defer_to_bucket_acls
;
398 std::map
<string
, string
, ltstr_nocase
> env_map
;
402 void init(CephContext
*cct
);
403 void init(CephContext
*cct
, char **envp
);
404 void set(const boost::string_ref
& name
, const boost::string_ref
& val
);
405 const char *get(const char *name
, const char *def_val
= nullptr) const;
406 int get_int(const char *name
, int def_val
= 0) const;
407 bool get_bool(const char *name
, bool def_val
= 0);
408 size_t get_size(const char *name
, size_t def_val
= 0) const;
409 bool exists(const char *name
) const;
410 bool exists_prefix(const char *prefix
) const;
412 void remove(const char *name
);
414 const std::map
<string
, string
, ltstr_nocase
>& get_map() const { return env_map
; }
434 RGW_OP_GET_BUCKET_LOGGING
,
435 RGW_OP_GET_BUCKET_VERSIONING
,
436 RGW_OP_SET_BUCKET_VERSIONING
,
437 RGW_OP_GET_BUCKET_WEBSITE
,
438 RGW_OP_SET_BUCKET_WEBSITE
,
440 RGW_OP_CREATE_BUCKET
,
441 RGW_OP_DELETE_BUCKET
,
445 RGW_OP_PUT_METADATA_ACCOUNT
,
446 RGW_OP_PUT_METADATA_BUCKET
,
447 RGW_OP_PUT_METADATA_OBJECT
,
457 RGW_OP_GET_REQUEST_PAYMENT
,
458 RGW_OP_SET_REQUEST_PAYMENT
,
459 RGW_OP_INIT_MULTIPART
,
460 RGW_OP_COMPLETE_MULTIPART
,
461 RGW_OP_ABORT_MULTIPART
,
462 RGW_OP_LIST_MULTIPART
,
463 RGW_OP_LIST_BUCKET_MULTIPARTS
,
464 RGW_OP_DELETE_MULTI_OBJ
,
467 RGW_OP_GET_CROSS_DOMAIN_POLICY
,
468 RGW_OP_GET_HEALTH_CHECK
,
475 RGW_OP_PUT_ROLE_POLICY
,
476 RGW_OP_GET_ROLE_POLICY
,
477 RGW_OP_LIST_ROLE_POLICIES
,
478 RGW_OP_DELETE_ROLE_POLICY
,
479 RGW_OP_PUT_BUCKET_POLICY
,
480 RGW_OP_GET_BUCKET_POLICY
,
481 RGW_OP_DELETE_BUCKET_POLICY
,
482 RGW_OP_PUT_OBJ_TAGGING
,
483 RGW_OP_GET_OBJ_TAGGING
,
484 RGW_OP_DELETE_OBJ_TAGGING
,
486 RGW_OP_ADMIN_SET_METADATA
,
487 RGW_OP_GET_OBJ_LAYOUT
,
489 RGW_OP_METADATA_SEARCH
,
490 RGW_OP_CONFIG_BUCKET_META_SEARCH
,
491 RGW_OP_GET_BUCKET_META_SEARCH
,
492 RGW_OP_DEL_BUCKET_META_SEARCH
,
495 class RGWAccessControlPolicy
;
498 struct RGWAccessKey
{
499 string id
; // AccessKey
500 string key
; // SecretKey
504 RGWAccessKey(std::string _id
, std::string _key
)
505 : id(std::move(_id
)), key(std::move(_key
)) {}
507 void encode(bufferlist
& bl
) const {
508 ENCODE_START(2, 2, bl
);
511 ::encode(subuser
, bl
);
515 void decode(bufferlist::iterator
& bl
) {
516 DECODE_START_LEGACY_COMPAT_LEN_32(2, 2, 2, bl
);
519 ::decode(subuser
, bl
);
522 void dump(Formatter
*f
) const;
523 void dump_plain(Formatter
*f
) const;
524 void dump(Formatter
*f
, const string
& user
, bool swift
) const;
525 static void generate_test_instances(list
<RGWAccessKey
*>& o
);
527 void decode_json(JSONObj
*obj
);
528 void decode_json(JSONObj
*obj
, bool swift
);
530 WRITE_CLASS_ENCODER(RGWAccessKey
)
536 RGWSubUser() : perm_mask(0) {}
537 void encode(bufferlist
& bl
) const {
538 ENCODE_START(2, 2, bl
);
540 ::encode(perm_mask
, bl
);
544 void decode(bufferlist::iterator
& bl
) {
545 DECODE_START_LEGACY_COMPAT_LEN_32(2, 2, 2, bl
);
547 ::decode(perm_mask
, bl
);
550 void dump(Formatter
*f
) const;
551 void dump(Formatter
*f
, const string
& user
) const;
552 static void generate_test_instances(list
<RGWSubUser
*>& o
);
554 void decode_json(JSONObj
*obj
);
556 WRITE_CLASS_ENCODER(RGWSubUser
)
560 map
<string
, uint32_t> caps
;
562 int get_cap(const string
& cap
, string
& type
, uint32_t *perm
);
563 int add_cap(const string
& cap
);
564 int remove_cap(const string
& cap
);
566 static int parse_cap_perm(const string
& str
, uint32_t *perm
);
567 int add_from_string(const string
& str
);
568 int remove_from_string(const string
& str
);
570 void encode(bufferlist
& bl
) const {
571 ENCODE_START(1, 1, bl
);
575 void decode(bufferlist::iterator
& bl
) {
580 int check_cap(const string
& cap
, uint32_t perm
);
581 bool is_valid_cap_type(const string
& tp
);
582 void dump(Formatter
*f
) const;
583 void dump(Formatter
*f
, const char *name
) const;
585 void decode_json(JSONObj
*obj
);
587 WRITE_CLASS_ENCODER(RGWUserCaps
)
589 void encode_json(const char *name
, const obj_version
& v
, Formatter
*f
);
590 void encode_json(const char *name
, const RGWUserCaps
& val
, Formatter
*f
);
592 void decode_json_obj(obj_version
& v
, JSONObj
*obj
);
594 enum RGWUserSourceType
608 map
<string
, RGWAccessKey
> access_keys
;
609 map
<string
, RGWAccessKey
> swift_keys
;
610 map
<string
, RGWSubUser
> subusers
;
617 string default_placement
;
618 list
<string
> placement_tags
;
619 RGWQuotaInfo bucket_quota
;
620 map
<int, string
> temp_url_keys
;
621 RGWQuotaInfo user_quota
;
627 max_buckets(RGW_DEFAULT_MAX_BUCKETS
),
628 op_mask(RGW_OP_TYPE_ALL
),
634 RGWAccessKey
* get_key0() {
635 if (access_keys
.empty())
638 return &(access_keys
.begin()->second
);
641 void encode(bufferlist
& bl
) const {
642 ENCODE_START(19, 9, bl
);
646 if (!access_keys
.empty()) {
647 map
<string
, RGWAccessKey
>::const_iterator iter
= access_keys
.begin();
648 const RGWAccessKey
& k
= iter
->second
;
652 ::encode(access_key
, bl
);
653 ::encode(secret_key
, bl
);
654 ::encode(display_name
, bl
);
655 ::encode(user_email
, bl
);
658 if (!swift_keys
.empty()) {
659 map
<string
, RGWAccessKey
>::const_iterator iter
= swift_keys
.begin();
660 const RGWAccessKey
& k
= iter
->second
;
664 ::encode(swift_name
, bl
);
665 ::encode(swift_key
, bl
);
666 ::encode(user_id
.id
, bl
);
667 ::encode(access_keys
, bl
);
668 ::encode(subusers
, bl
);
669 ::encode(suspended
, bl
);
670 ::encode(swift_keys
, bl
);
671 ::encode(max_buckets
, bl
);
673 ::encode(op_mask
, bl
);
674 ::encode(system
, bl
);
675 ::encode(default_placement
, bl
);
676 ::encode(placement_tags
, bl
);
677 ::encode(bucket_quota
, bl
);
678 ::encode(temp_url_keys
, bl
);
679 ::encode(user_quota
, bl
);
680 ::encode(user_id
.tenant
, bl
);
685 void decode(bufferlist::iterator
& bl
) {
686 DECODE_START_LEGACY_COMPAT_LEN_32(19, 9, 9, bl
);
687 if (struct_v
>= 2) ::decode(auid
, bl
);
688 else auid
= CEPH_AUTH_UID_DEFAULT
;
691 ::decode(access_key
, bl
);
692 ::decode(secret_key
, bl
);
697 access_keys
[access_key
] = k
;
699 ::decode(display_name
, bl
);
700 ::decode(user_email
, bl
);
701 /* We populate swift_keys map later nowadays, but we have to decode. */
704 if (struct_v
>= 3) ::decode(swift_name
, bl
);
705 if (struct_v
>= 4) ::decode(swift_key
, bl
);
707 ::decode(user_id
.id
, bl
);
709 user_id
.id
= access_key
;
711 ::decode(access_keys
, bl
);
712 ::decode(subusers
, bl
);
716 ::decode(suspended
, bl
);
719 ::decode(swift_keys
, bl
);
721 if (struct_v
>= 10) {
722 ::decode(max_buckets
, bl
);
724 max_buckets
= RGW_DEFAULT_MAX_BUCKETS
;
726 if (struct_v
>= 11) {
729 if (struct_v
>= 12) {
730 ::decode(op_mask
, bl
);
732 op_mask
= RGW_OP_TYPE_ALL
;
734 if (struct_v
>= 13) {
735 ::decode(system
, bl
);
736 ::decode(default_placement
, bl
);
737 ::decode(placement_tags
, bl
); /* tags of allowed placement rules */
739 if (struct_v
>= 14) {
740 ::decode(bucket_quota
, bl
);
742 if (struct_v
>= 15) {
743 ::decode(temp_url_keys
, bl
);
745 if (struct_v
>= 16) {
746 ::decode(user_quota
, bl
);
748 if (struct_v
>= 17) {
749 ::decode(user_id
.tenant
, bl
);
751 user_id
.tenant
.clear();
753 if (struct_v
>= 18) {
756 if (struct_v
>= 19) {
761 void dump(Formatter
*f
) const;
762 static void generate_test_instances(list
<RGWUserInfo
*>& o
);
764 void decode_json(JSONObj
*obj
);
766 WRITE_CLASS_ENCODER(RGWUserInfo
)
773 rgw_pool(const rgw_pool
& _p
) : name(_p
.name
), ns(_p
.ns
) {}
774 rgw_pool(const string
& _s
) {
777 rgw_pool(const string
& _name
, const string
& _ns
) : name(_name
), ns(_ns
) {}
779 string
to_str() const;
780 void from_str(const string
& s
);
782 void init(const string
& _s
) {
790 int compare(const rgw_pool
& p
) const {
791 int r
= name
.compare(p
.name
);
795 return ns
.compare(p
.ns
);
798 void encode(bufferlist
& bl
) const {
799 ENCODE_START(10, 10, bl
);
805 void decode_from_bucket(bufferlist::iterator
& bl
);
807 void decode(bufferlist::iterator
& bl
) {
808 DECODE_START_LEGACY_COMPAT_LEN(10, 3, 3, bl
);
815 * note that rgw_pool can be used where rgw_bucket was used before
816 * therefore we inherit rgw_bucket's old versions. However, we only
817 * need the first field from rgw_bucket. unless we add more fields
818 * in which case we'll need to look at struct_v, and check the actual
819 * version. Anything older than 10 needs to be treated as old rgw_bucket
829 bool operator==(const rgw_pool
& p
) const {
830 return (compare(p
) == 0);
832 bool operator!=(const rgw_pool
& p
) const {
833 return !(*this == p
);
835 bool operator<(const rgw_pool
& p
) const {
836 int r
= name
.compare(p
.name
);
838 return (ns
.compare(p
.ns
) < 0);
843 WRITE_CLASS_ENCODER(rgw_pool
)
845 struct rgw_data_placement_target
{
847 rgw_pool data_extra_pool
;
850 rgw_data_placement_target() {}
852 rgw_data_placement_target(const rgw_pool
& _data_pool
, const rgw_pool
& _data_extra_pool
, const rgw_pool
& _index_pool
)
853 : data_pool(_data_pool
), data_extra_pool(_data_extra_pool
), index_pool(_index_pool
) {}
855 const rgw_pool
& get_data_extra_pool() const {
856 if (data_extra_pool
.empty()) {
859 return data_extra_pool
;
862 int compare(const rgw_data_placement_target
& t
) {
863 int c
= data_pool
.compare(t
.data_pool
);
867 c
= data_extra_pool
.compare(t
.data_extra_pool
);
871 return index_pool
.compare(t
.index_pool
);
874 void dump(Formatter
*f
) const;
875 void decode_json(JSONObj
*obj
);
878 inline ostream
& operator<<(ostream
& out
, const rgw_pool
& p
) {
889 rgw_raw_obj(const rgw_pool
& _pool
, const std::string
& _oid
) {
892 rgw_raw_obj(const rgw_pool
& _pool
, const std::string
& _oid
, const string
& _loc
) : loc(_loc
) {
896 void init(const rgw_pool
& _pool
, const std::string
& _oid
) {
905 void encode(bufferlist
& bl
) const {
906 ENCODE_START(6, 6, bl
);
913 void decode_from_rgw_obj(bufferlist::iterator
& bl
);
915 void decode(bufferlist::iterator
& bl
) {
916 unsigned ofs
= bl
.get_off();
920 * this object was encoded as rgw_obj, prior to rgw_raw_obj been split out of it,
921 * let's decode it as rgw_obj and convert it
924 decode_from_rgw_obj(bl
);
933 bool operator<(const rgw_raw_obj
& o
) const {
934 int r
= pool
.compare(o
.pool
);
936 r
= oid
.compare(o
.oid
);
938 r
= loc
.compare(o
.loc
);
944 bool operator==(const rgw_raw_obj
& o
) const {
945 return (pool
== o
.pool
&& oid
== o
.oid
&& loc
== o
.loc
);
948 void dump(Formatter
*f
) const;
949 void decode_json(JSONObj
*obj
);
951 WRITE_CLASS_ENCODER(rgw_raw_obj
)
953 inline ostream
& operator<<(ostream
& out
, const rgw_raw_obj
& o
) {
954 out
<< o
.pool
<< ":" << o
.oid
;
962 std::string bucket_id
;
963 rgw_data_placement_target explicit_placement
;
966 * runtime in-memory only info. If not empty, points to the bucket instance object
970 // cppcheck-suppress noExplicitConstructor
971 explicit rgw_bucket(const rgw_user
& u
, const cls_user_bucket
& b
) :
975 bucket_id(b
.bucket_id
),
976 explicit_placement(b
.explicit_placement
.data_pool
,
977 b
.explicit_placement
.data_extra_pool
,
978 b
.explicit_placement
.index_pool
) {}
980 void convert(cls_user_bucket
*b
) const {
983 b
->bucket_id
= bucket_id
;
984 b
->explicit_placement
.data_pool
= explicit_placement
.data_pool
.to_str();
985 b
->explicit_placement
.data_extra_pool
= explicit_placement
.data_extra_pool
.to_str();
986 b
->explicit_placement
.index_pool
= explicit_placement
.index_pool
.to_str();
989 void encode(bufferlist
& bl
) const {
990 ENCODE_START(10, 10, bl
);
992 ::encode(marker
, bl
);
993 ::encode(bucket_id
, bl
);
994 ::encode(tenant
, bl
);
995 bool encode_explicit
= !explicit_placement
.data_pool
.empty();
996 ::encode(encode_explicit
, bl
);
997 if (encode_explicit
) {
998 ::encode(explicit_placement
.data_pool
, bl
);
999 ::encode(explicit_placement
.data_extra_pool
, bl
);
1000 ::encode(explicit_placement
.index_pool
, bl
);
1004 void decode(bufferlist::iterator
& bl
) {
1005 DECODE_START_LEGACY_COMPAT_LEN(10, 3, 3, bl
);
1007 if (struct_v
< 10) {
1008 ::decode(explicit_placement
.data_pool
.name
, bl
);
1010 if (struct_v
>= 2) {
1011 ::decode(marker
, bl
);
1012 if (struct_v
<= 3) {
1016 snprintf(buf
, sizeof(buf
), "%llu", (long long)id
);
1019 ::decode(bucket_id
, bl
);
1022 if (struct_v
< 10) {
1023 if (struct_v
>= 5) {
1024 ::decode(explicit_placement
.index_pool
.name
, bl
);
1026 explicit_placement
.index_pool
= explicit_placement
.data_pool
;
1028 if (struct_v
>= 7) {
1029 ::decode(explicit_placement
.data_extra_pool
.name
, bl
);
1032 if (struct_v
>= 8) {
1033 ::decode(tenant
, bl
);
1035 if (struct_v
>= 10) {
1036 bool decode_explicit
= !explicit_placement
.data_pool
.empty();
1037 ::decode(decode_explicit
, bl
);
1038 if (decode_explicit
) {
1039 ::decode(explicit_placement
.data_pool
, bl
);
1040 ::decode(explicit_placement
.data_extra_pool
, bl
);
1041 ::decode(explicit_placement
.index_pool
, bl
);
1047 void update_bucket_id(const string
& new_bucket_id
) {
1048 bucket_id
= new_bucket_id
;
1052 // format a key for the bucket/instance. pass delim=0 to skip a field
1053 std::string
get_key(char tenant_delim
= '/',
1054 char id_delim
= ':') const;
1056 const rgw_pool
& get_data_extra_pool() const {
1057 return explicit_placement
.get_data_extra_pool();
1060 void dump(Formatter
*f
) const;
1061 void decode_json(JSONObj
*obj
);
1062 static void generate_test_instances(list
<rgw_bucket
*>& o
);
1064 bool operator<(const rgw_bucket
& b
) const {
1065 return name
.compare(b
.name
) < 0;
1067 bool operator==(const rgw_bucket
& b
) const {
1068 return (name
== b
.name
) && (bucket_id
== b
.bucket_id
);
1071 WRITE_CLASS_ENCODER(rgw_bucket
)
1073 inline ostream
& operator<<(ostream
& out
, const rgw_bucket
&b
) {
1074 out
<< b
.name
<< "[" << b
.marker
<< "])";
1078 struct rgw_bucket_shard
{
1082 rgw_bucket_shard() : shard_id(-1) {}
1083 rgw_bucket_shard(const rgw_bucket
& _b
, int _sid
) : bucket(_b
), shard_id(_sid
) {}
1085 std::string
get_key(char tenant_delim
= '/', char id_delim
= ':',
1086 char shard_delim
= ':') const;
1088 bool operator<(const rgw_bucket_shard
& b
) const {
1089 if (bucket
< b
.bucket
) {
1092 if (b
.bucket
< bucket
) {
1095 return shard_id
< b
.shard_id
;
1100 struct RGWObjVersionTracker
{
1101 obj_version read_version
;
1102 obj_version write_version
;
1104 obj_version
*version_for_read() {
1105 return &read_version
;
1108 obj_version
*version_for_write() {
1109 if (write_version
.ver
== 0)
1112 return &write_version
;
1115 obj_version
*version_for_check() {
1116 if (read_version
.ver
== 0)
1119 return &read_version
;
1122 void prepare_op_for_read(librados::ObjectReadOperation
*op
);
1123 void prepare_op_for_write(librados::ObjectWriteOperation
*op
);
1125 void apply_write() {
1126 read_version
= write_version
;
1127 write_version
= obj_version();
1131 read_version
= obj_version();
1132 write_version
= obj_version();
1135 void generate_new_write_ver(CephContext
*cct
);
1138 enum RGWBucketFlags
{
1139 BUCKET_SUSPENDED
= 0x1,
1140 BUCKET_VERSIONED
= 0x2,
1141 BUCKET_VERSIONS_SUSPENDED
= 0x4,
1144 enum RGWBucketIndexType
{
1145 RGWBIType_Normal
= 0,
1146 RGWBIType_Indexless
= 1,
1149 inline ostream
& operator<<(ostream
& out
, const RGWBucketIndexType
&index_type
)
1151 switch (index_type
) {
1152 case RGWBIType_Normal
:
1153 return out
<< "Normal";
1154 case RGWBIType_Indexless
:
1155 return out
<< "Indexless";
1157 return out
<< "Unknown";
1161 struct RGWBucketInfo
1163 enum BIShardsHashType
{
1171 ceph::real_time creation_time
;
1172 string placement_rule
;
1173 bool has_instance_obj
;
1174 RGWObjVersionTracker objv_tracker
; /* we don't need to serialize this, for runtime tracking */
1175 obj_version ep_objv
; /* entry point object version, for runtime tracking only */
1178 // Represents the number of bucket index object shards:
1179 // - value of 0 indicates there is no sharding (this is by default before this
1180 // feature is implemented).
1181 // - value of UINT32_T::MAX indicates this is a blind bucket.
1182 uint32_t num_shards
;
1184 // Represents the bucket index shard hash type.
1185 uint8_t bucket_index_shard_hash_type
;
1187 // Represents the shard number for blind bucket.
1188 const static uint32_t NUM_SHARDS_BLIND_BUCKET
;
1190 bool requester_pays
;
1193 RGWBucketWebsiteConf website_conf
;
1195 RGWBucketIndexType index_type
;
1197 bool swift_versioning
;
1198 string swift_ver_location
;
1200 map
<string
, uint32_t> mdsearch_config
;
1203 uint8_t reshard_status
;
1204 string new_bucket_instance_id
;
1206 void encode(bufferlist
& bl
) const {
1207 ENCODE_START(19, 4, bl
);
1208 ::encode(bucket
, bl
);
1209 ::encode(owner
.id
, bl
);
1210 ::encode(flags
, bl
);
1211 ::encode(zonegroup
, bl
);
1212 uint64_t ct
= real_clock::to_time_t(creation_time
);
1214 ::encode(placement_rule
, bl
);
1215 ::encode(has_instance_obj
, bl
);
1216 ::encode(quota
, bl
);
1217 ::encode(num_shards
, bl
);
1218 ::encode(bucket_index_shard_hash_type
, bl
);
1219 ::encode(requester_pays
, bl
);
1220 ::encode(owner
.tenant
, bl
);
1221 ::encode(has_website
, bl
);
1223 ::encode(website_conf
, bl
);
1225 ::encode((uint32_t)index_type
, bl
);
1226 ::encode(swift_versioning
, bl
);
1227 if (swift_versioning
) {
1228 ::encode(swift_ver_location
, bl
);
1230 ::encode(creation_time
, bl
);
1231 ::encode(mdsearch_config
, bl
);
1232 ::encode(reshard_status
, bl
);
1233 ::encode(new_bucket_instance_id
, bl
);
1236 void decode(bufferlist::iterator
& bl
) {
1237 DECODE_START_LEGACY_COMPAT_LEN_32(19, 4, 4, bl
);
1238 ::decode(bucket
, bl
);
1239 if (struct_v
>= 2) {
1245 ::decode(flags
, bl
);
1247 ::decode(zonegroup
, bl
);
1248 if (struct_v
>= 6) {
1252 creation_time
= ceph::real_clock::from_time_t((time_t)ct
);
1255 ::decode(placement_rule
, bl
);
1257 ::decode(has_instance_obj
, bl
);
1259 ::decode(quota
, bl
);
1261 ::decode(num_shards
, bl
);
1263 ::decode(bucket_index_shard_hash_type
, bl
);
1265 ::decode(requester_pays
, bl
);
1267 ::decode(owner
.tenant
, bl
);
1268 if (struct_v
>= 14) {
1269 ::decode(has_website
, bl
);
1271 ::decode(website_conf
, bl
);
1273 website_conf
= RGWBucketWebsiteConf();
1276 if (struct_v
>= 15) {
1279 index_type
= (RGWBucketIndexType
)it
;
1281 index_type
= RGWBIType_Normal
;
1283 swift_versioning
= false;
1284 swift_ver_location
.clear();
1285 if (struct_v
>= 16) {
1286 ::decode(swift_versioning
, bl
);
1287 if (swift_versioning
) {
1288 ::decode(swift_ver_location
, bl
);
1291 if (struct_v
>= 17) {
1292 ::decode(creation_time
, bl
);
1294 if (struct_v
>= 18) {
1295 ::decode(mdsearch_config
, bl
);
1297 if (struct_v
>= 19) {
1298 ::decode(reshard_status
, bl
);
1299 ::decode(new_bucket_instance_id
, bl
);
1303 void dump(Formatter
*f
) const;
1304 static void generate_test_instances(list
<RGWBucketInfo
*>& o
);
1306 void decode_json(JSONObj
*obj
);
1308 bool versioned() const { return (flags
& BUCKET_VERSIONED
) != 0; }
1309 int versioning_status() { return flags
& (BUCKET_VERSIONED
| BUCKET_VERSIONS_SUSPENDED
); }
1310 bool versioning_enabled() { return versioning_status() == BUCKET_VERSIONED
; }
1312 bool has_swift_versioning() const {
1313 /* A bucket may be versioned through one mechanism only. */
1314 return swift_versioning
&& !versioned();
1317 RGWBucketInfo() : flags(0), has_instance_obj(false), num_shards(0), bucket_index_shard_hash_type(MOD
), requester_pays(false),
1318 has_website(false), swift_versioning(false), reshard_status(0) {}
1320 WRITE_CLASS_ENCODER(RGWBucketInfo
)
1322 struct RGWBucketEntryPoint
1326 ceph::real_time creation_time
;
1329 bool has_bucket_info
;
1330 RGWBucketInfo old_bucket_info
;
1332 RGWBucketEntryPoint() : linked(false), has_bucket_info(false) {}
1334 void encode(bufferlist
& bl
) const {
1335 ENCODE_START(10, 8, bl
);
1336 ::encode(bucket
, bl
);
1337 ::encode(owner
.id
, bl
);
1338 ::encode(linked
, bl
);
1339 uint64_t ctime
= (uint64_t)real_clock::to_time_t(creation_time
);
1340 ::encode(ctime
, bl
);
1341 ::encode(owner
, bl
);
1342 ::encode(creation_time
, bl
);
1345 void decode(bufferlist::iterator
& bl
) {
1346 bufferlist::iterator orig_iter
= bl
;
1347 DECODE_START_LEGACY_COMPAT_LEN_32(10, 4, 4, bl
);
1349 /* ouch, old entry, contains the bucket info itself */
1350 old_bucket_info
.decode(orig_iter
);
1351 has_bucket_info
= true;
1354 has_bucket_info
= false;
1355 ::decode(bucket
, bl
);
1356 ::decode(owner
.id
, bl
);
1357 ::decode(linked
, bl
);
1359 ::decode(ctime
, bl
);
1360 if (struct_v
< 10) {
1361 creation_time
= real_clock::from_time_t((time_t)ctime
);
1363 if (struct_v
>= 9) {
1364 ::decode(owner
, bl
);
1366 if (struct_v
>= 10) {
1367 ::decode(creation_time
, bl
);
1372 void dump(Formatter
*f
) const;
1373 void decode_json(JSONObj
*obj
);
1375 WRITE_CLASS_ENCODER(RGWBucketEntryPoint
)
1377 struct RGWStorageStats
1379 RGWObjCategory category
;
1381 uint64_t size_rounded
;
1382 uint64_t size_utilized
{0}; //< size after compression, encryption
1383 uint64_t num_objects
;
1386 : category(RGW_OBJ_CATEGORY_NONE
),
1391 void dump(Formatter
*f
) const;
1396 /* Namespaced forward declarations. */
1400 class AWSBrowserUploadAbstractor
;
1413 map
<string
, string
> x_meta_map
;
1419 string request_uri_aws4
;
1420 string effective_uri
;
1421 string request_params
;
1424 req_info(CephContext
*cct
, const RGWEnv
*env
);
1425 void rebuild_from(req_info
& src
);
1426 void init_meta_info(bool *found_bad_meta
);
1429 typedef cls_rgw_obj_key rgw_obj_index_key
;
1431 struct rgw_obj_key
{
1437 // cppcheck-suppress noExplicitConstructor
1438 rgw_obj_key(const string
& n
) : name(n
) {}
1439 rgw_obj_key(const string
& n
, const string
& i
) : name(n
), instance(i
) {}
1440 rgw_obj_key(const string
& n
, const string
& i
, const string
& _ns
) : name(n
), instance(i
), ns(_ns
) {}
1442 rgw_obj_key(const rgw_obj_index_key
& k
) {
1443 parse_index_key(k
.name
, &name
, &ns
);
1444 instance
= k
.instance
;
1447 static void parse_index_key(const string
& key
, string
*name
, string
*ns
) {
1448 if (key
[0] != '_') {
1453 if (key
[1] == '_') {
1454 *name
= key
.substr(1);
1458 ssize_t pos
= key
.find('_', 1);
1460 /* shouldn't happen, just use key */
1466 *name
= key
.substr(pos
+ 1);
1467 *ns
= key
.substr(1, pos
-1);
1470 void set(const string
& n
) {
1476 void set(const string
& n
, const string
& i
) {
1482 void set(const string
& n
, const string
& i
, const string
& _ns
) {
1488 bool set(const rgw_obj_index_key
& index_key
) {
1489 if (!parse_raw_oid(index_key
.name
, this)) {
1492 instance
= index_key
.instance
;
1496 void set_instance(const string
& i
) {
1500 string
get_index_key_name() const {
1502 if (name
.size() < 1 || name
[0] != '_') {
1505 return string("_") + name
;
1508 char buf
[ns
.size() + 16];
1509 snprintf(buf
, sizeof(buf
), "_%s_", ns
.c_str());
1510 return string(buf
) + name
;
1513 void get_index_key(rgw_obj_index_key
*key
) const {
1514 key
->name
= get_index_key_name();
1515 key
->instance
= instance
;
1518 string
get_loc() const {
1520 * For backward compatibility. Older versions used to have object locator on all objects,
1521 * however, the name was the effective object locator. This had the same effect as not
1522 * having object locator at all for most objects but the ones that started with underscore as
1523 * these were escaped.
1525 if (name
[0] == '_' && ns
.empty()) {
1532 bool empty() const {
1533 return name
.empty();
1536 bool have_null_instance() const {
1537 return instance
== "null";
1540 bool have_instance() const {
1541 return !instance
.empty();
1544 bool need_to_encode_instance() const {
1545 return have_instance() && !have_null_instance();
1548 string
get_oid() const {
1549 if (ns
.empty() && !need_to_encode_instance()) {
1550 if (name
.size() < 1 || name
[0] != '_') {
1553 return string("_") + name
;
1558 if (need_to_encode_instance()) {
1559 oid
.append(string(":") + instance
);
1566 bool operator==(const rgw_obj_key
& k
) const {
1567 return (name
.compare(k
.name
) == 0) &&
1568 (instance
.compare(k
.instance
) == 0);
1571 bool operator<(const rgw_obj_key
& k
) const {
1572 int r
= name
.compare(k
.name
);
1574 r
= instance
.compare(k
.instance
);
1579 bool operator<=(const rgw_obj_key
& k
) const {
1580 return !(k
< *this);
1583 static void parse_ns_field(string
& ns
, string
& instance
) {
1584 int pos
= ns
.find(':');
1586 instance
= ns
.substr(pos
+ 1);
1587 ns
= ns
.substr(0, pos
);
1593 static bool parse_raw_oid(const string
& oid
, rgw_obj_key
*key
) {
1594 key
->instance
.clear();
1596 if (oid
[0] != '_') {
1601 if (oid
.size() >= 2 && oid
[1] == '_') {
1602 key
->name
= oid
.substr(1);
1606 if (oid
[0] != '_' || oid
.size() < 3) // for namespace, min size would be 3: _x_
1609 int pos
= oid
.find('_', 1);
1610 if (pos
<= 1) // if it starts with __, it's not in our namespace
1613 key
->ns
= oid
.substr(1, pos
- 1);
1614 parse_ns_field(key
->ns
, key
->instance
);
1616 key
->name
= oid
.substr(pos
+ 1);
1621 * Translate a namespace-mangled object name to the user-facing name
1622 * existing in the given namespace.
1624 * If the object is part of the given namespace, it returns true
1625 * and cuts down the name to the unmangled version. If it is not
1626 * part of the given namespace, it returns false.
1628 static bool oid_to_key_in_ns(const string
& oid
, rgw_obj_key
*key
, const string
& ns
) {
1630 bool ret
= parse_raw_oid(oid
, key
);
1635 return (ns
== key
->ns
);
1639 * Given a mangled object name and an empty namespace string, this
1640 * function extracts the namespace into the string and sets the object
1641 * name to be the unmangled version.
1643 * It returns true after successfully doing so, or
1644 * false if it fails.
1646 static bool strip_namespace_from_name(string
& name
, string
& ns
, string
& instance
) {
1649 if (name
[0] != '_') {
1653 size_t pos
= name
.find('_', 1);
1654 if (pos
== string::npos
) {
1658 if (name
[1] == '_') {
1659 name
= name
.substr(1);
1663 size_t period_pos
= name
.find('.');
1664 if (period_pos
< pos
) {
1668 ns
= name
.substr(1, pos
-1);
1669 name
= name
.substr(pos
+1, string::npos
);
1671 parse_ns_field(ns
, instance
);
1675 void encode(bufferlist
& bl
) const {
1676 ENCODE_START(2, 1, bl
);
1678 ::encode(instance
, bl
);
1682 void decode(bufferlist::iterator
& bl
) {
1683 DECODE_START(2, bl
);
1685 ::decode(instance
, bl
);
1686 if (struct_v
>= 2) {
1691 void dump(Formatter
*f
) const;
1693 WRITE_CLASS_ENCODER(rgw_obj_key
)
1695 inline ostream
& operator<<(ostream
& out
, const rgw_obj_key
&o
) {
1696 if (o
.instance
.empty()) {
1697 return out
<< o
.name
;
1699 return out
<< o
.name
<< "[" << o
.instance
<< "]";
1703 inline ostream
& operator<<(ostream
& out
, const rgw_obj_index_key
&o
) {
1704 if (o
.instance
.empty()) {
1705 return out
<< o
.name
;
1707 return out
<< o
.name
<< "[" << o
.instance
<< "]";
1711 struct req_init_state
{
1712 /* Keeps [[tenant]:]bucket until we parse the token. */
1717 /* XXX why don't RGWRequest (or descendants) hold this state? */
1720 #include "rgw_auth.h"
1722 /** Store all the state necessary to complete and respond to an HTTP request*/
1725 rgw::io::BasicClient
*cio
;
1726 RGWRequest
*req
{nullptr}; /// XXX: re-remove??
1728 RGWOpType op_type
{};
1729 bool content_started
;
1731 ceph::Formatter
*formatter
;
1733 string relative_uri
;
1735 int64_t content_length
;
1736 map
<string
, string
> generic_attrs
;
1740 bool enable_ops_log
;
1741 bool enable_usage_log
;
1742 uint8_t defer_to_bucket_acls
;
1745 /* Set once when url_bucket is parsed and not violated thereafter. */
1746 string account_name
;
1748 string bucket_tenant
;
1753 string src_tenant_name
;
1754 string src_bucket_name
;
1755 rgw_obj_key src_object
;
1756 ACLOwner bucket_owner
;
1759 string zonegroup_name
;
1760 string zonegroup_endpoint
;
1761 string bucket_instance_id
;
1762 int bucket_instance_shard_id
;
1766 RGWBucketInfo bucket_info
;
1767 map
<string
, bufferlist
> bucket_attrs
;
1775 /* TODO(rzarzynski): switch out to the static_ptr for both members. */
1777 /* Object having the knowledge about an authenticated identity and allowing
1778 * to apply it during the authorization phase (verify_permission() methods
1779 * of a given RGWOp). Thus, it bounds authentication and authorization steps
1780 * through a well-defined interface. For more details, see rgw_auth.h. */
1781 std::unique_ptr
<rgw::auth::Identity
> identity
;
1783 std::shared_ptr
<rgw::auth::Completer
> completer
;
1785 /* A container for credentials of the S3's browser upload. It's necessary
1786 * because: 1) the ::authenticate() method of auth engines and strategies
1787 * take req_state only; 2) auth strategies live much longer than RGWOps -
1788 * there is no way to pass additional data dependencies through ctors. */
1791 friend class RGWPostObj_ObjStore_S3
;
1793 friend class rgw::auth::s3::AWSBrowserUploadAbstractor
;
1795 std::string access_key
;
1796 std::string signature
;
1797 std::string x_amz_algorithm
;
1798 std::string x_amz_credential
;
1799 std::string x_amz_date
;
1800 ceph::bufferlist encoded_policy
;
1804 std::unique_ptr
<RGWAccessControlPolicy
> user_acl
;
1805 RGWAccessControlPolicy
*bucket_acl
;
1806 RGWAccessControlPolicy
*object_acl
;
1808 rgw::IAM::Environment env
;
1809 boost::optional
<rgw::IAM::Policy
> iam_policy
;
1811 /* Is the request made by an user marked as a system one?
1812 * Being system user means we also have the admin status. */
1813 bool system_request
;
1816 bool has_acl_header
;
1817 bool local_source
; /* source is local */
1821 /* Content-Disposition override for TempURL of Swift API. */
1830 req_init_state init_state
;
1838 req_state(CephContext
* _cct
, RGWEnv
* e
, RGWUserInfo
* u
);
1841 bool is_err() const { return err
.is_err(); }
1844 void set_req_state_err(struct req_state
*, int);
1845 void set_req_state_err(struct req_state
*, int, const string
&);
1846 void set_req_state_err(struct rgw_err
&, int, const int);
1847 void dump(struct req_state
*);
1849 /** Store basic data on bucket */
1850 struct RGWBucketEnt
{
1853 size_t size_rounded
;
1854 real_time creation_time
;
1857 RGWBucketEnt() : size(0), size_rounded(0), count(0) {}
1859 explicit RGWBucketEnt(const rgw_user
& u
, const cls_user_bucket_entry
& e
)
1860 : bucket(u
, e
.bucket
),
1862 size_rounded(e
.size_rounded
),
1863 creation_time(e
.creation_time
),
1867 void convert(cls_user_bucket_entry
*b
) const {
1868 bucket
.convert(&b
->bucket
);
1870 b
->size_rounded
= size_rounded
;
1871 b
->creation_time
= creation_time
;
1875 void encode(bufferlist
& bl
) const {
1876 ENCODE_START(6, 5, bl
);
1878 __u32 mt
= ceph::real_clock::to_time_t(creation_time
);
1879 string empty_str
; // originally had the bucket name here, but we encode bucket later
1880 ::encode(empty_str
, bl
);
1883 ::encode(count
, bl
);
1884 ::encode(bucket
, bl
);
1887 ::encode(creation_time
, bl
);
1890 void decode(bufferlist::iterator
& bl
) {
1891 DECODE_START_LEGACY_COMPAT_LEN(6, 5, 5, bl
);
1894 string empty_str
; // backward compatibility
1895 ::decode(empty_str
, bl
);
1900 creation_time
= ceph::real_clock::from_time_t(mt
);
1903 ::decode(count
, bl
);
1905 ::decode(bucket
, bl
);
1910 ::decode(creation_time
, bl
);
1913 void dump(Formatter
*f
) const;
1914 static void generate_test_instances(list
<RGWBucketEnt
*>& o
);
1916 WRITE_CLASS_ENCODER(RGWBucketEnt
)
1922 bool in_extra_data
{false}; /* in-memory only member, does not serialize */
1924 // Represents the hash index source for this object once it is set (non-empty)
1925 std::string index_hash_source
;
1928 rgw_obj(const rgw_bucket
& b
, const std::string
& name
) : bucket(b
), key(name
) {}
1929 rgw_obj(const rgw_bucket
& b
, const rgw_obj_key
& k
) : bucket(b
), key(k
) {}
1930 rgw_obj(const rgw_bucket
& b
, const rgw_obj_index_key
& k
) : bucket(b
), key(k
) {}
1932 void init(const rgw_bucket
& b
, const std::string
& name
) {
1936 void init(const rgw_bucket
& b
, const std::string
& name
, const string
& i
, const string
& n
) {
1938 key
.set(name
, i
, n
);
1940 void init_ns(const rgw_bucket
& b
, const std::string
& name
, const string
& n
) {
1943 key
.instance
.clear();
1947 bool empty() const {
1951 void set_key(const rgw_obj_key
& k
) {
1955 string
get_oid() const {
1956 return key
.get_oid();
1959 const string
& get_hash_object() const {
1960 return index_hash_source
.empty() ? key
.name
: index_hash_source
;
1963 void set_in_extra_data(bool val
) {
1964 in_extra_data
= val
;
1967 bool is_in_extra_data() const {
1968 return in_extra_data
;
1971 void encode(bufferlist
& bl
) const {
1972 ENCODE_START(6, 6, bl
);
1973 ::encode(bucket
, bl
);
1974 ::encode(key
.ns
, bl
);
1975 ::encode(key
.name
, bl
);
1976 ::encode(key
.instance
, bl
);
1977 // ::encode(placement_id, bl);
1980 void decode(bufferlist::iterator
& bl
) {
1981 DECODE_START_LEGACY_COMPAT_LEN(6, 3, 3, bl
);
1984 ::decode(bucket
.name
, bl
); /* bucket.name */
1985 ::decode(s
, bl
); /* loc */
1986 ::decode(key
.ns
, bl
);
1987 ::decode(key
.name
, bl
);
1989 ::decode(bucket
, bl
);
1991 ::decode(key
.instance
, bl
);
1992 if (key
.ns
.empty() && key
.instance
.empty()) {
1993 if (key
.name
[0] == '_') {
1994 key
.name
= key
.name
.substr(1);
1997 if (struct_v
>= 5) {
1998 ::decode(key
.name
, bl
);
2000 ssize_t pos
= key
.name
.find('_', 1);
2002 throw buffer::error();
2004 key
.name
= key
.name
.substr(pos
);
2008 ::decode(bucket
, bl
);
2009 ::decode(key
.ns
, bl
);
2010 ::decode(key
.name
, bl
);
2011 ::decode(key
.instance
, bl
);
2012 // ::decode(placement_id, bl);
2016 void dump(Formatter
*f
) const;
2017 static void generate_test_instances(list
<rgw_obj
*>& o
);
2019 bool operator==(const rgw_obj
& o
) const {
2020 return (key
== o
.key
) &&
2021 (bucket
== o
.bucket
);
2023 bool operator<(const rgw_obj
& o
) const {
2024 int r
= key
.name
.compare(o
.key
.name
);
2026 r
= bucket
.bucket_id
.compare(o
.bucket
.bucket_id
); /* not comparing bucket.name, if bucket_id is equal so will be bucket.name */
2028 r
= key
.ns
.compare(o
.key
.ns
);
2030 r
= key
.instance
.compare(o
.key
.instance
);
2038 const rgw_pool
& get_explicit_data_pool() {
2039 if (!in_extra_data
|| bucket
.explicit_placement
.data_extra_pool
.empty()) {
2040 return bucket
.explicit_placement
.data_pool
;
2042 return bucket
.explicit_placement
.data_extra_pool
;
2045 WRITE_CLASS_ENCODER(rgw_obj
)
2047 struct rgw_cache_entry_info
{
2048 string cache_locator
;
2051 rgw_cache_entry_info() : gen(0) {}
2054 inline ostream
& operator<<(ostream
& out
, const rgw_obj
&o
) {
2055 return out
<< o
.bucket
.name
<< ":" << o
.get_oid();
2058 static inline void buf_to_hex(const unsigned char* const buf
,
2063 for (size_t i
= 0; i
< len
; i
++) {
2064 ::sprintf(&str
[i
*2], "%02x", static_cast<int>(buf
[i
]));
2068 template<size_t N
> static inline std::array
<char, N
* 2 + 1>
2069 buf_to_hex(const std::array
<unsigned char, N
>& buf
)
2071 static_assert(N
> 0, "The input array must be at least one element long");
2073 std::array
<char, N
* 2 + 1> hex_dest
;
2074 buf_to_hex(buf
.data(), N
, hex_dest
.data());
2078 static inline int hexdigit(char c
)
2080 if (c
>= '0' && c
<= '9')
2083 if (c
>= 'A' && c
<= 'F')
2084 return c
- 'A' + 0xa;
2088 static inline int hex_to_buf(const char *hex
, char *buf
, int len
)
2091 const char *p
= hex
;
2096 int d
= hexdigit(*p
);
2113 static inline int rgw_str_to_bool(const char *s
, int def_val
)
2118 return (strcasecmp(s
, "on") == 0 ||
2119 strcasecmp(s
, "yes") == 0 ||
2120 strcasecmp(s
, "1") == 0);
2123 static inline void append_rand_alpha(CephContext
*cct
, const string
& src
, string
& dest
, int len
)
2127 gen_rand_alphanumeric(cct
, buf
, len
);
2132 static inline const char *rgw_obj_category_name(RGWObjCategory category
)
2135 case RGW_OBJ_CATEGORY_NONE
:
2137 case RGW_OBJ_CATEGORY_MAIN
:
2139 case RGW_OBJ_CATEGORY_SHADOW
:
2140 return "rgw.shadow";
2141 case RGW_OBJ_CATEGORY_MULTIMETA
:
2142 return "rgw.multimeta";
2148 static inline uint64_t rgw_rounded_kb(uint64_t bytes
)
2150 return (bytes
+ 1023) / 1024;
2153 static inline uint64_t rgw_rounded_objsize(uint64_t bytes
)
2155 return ((bytes
+ 4095) & ~4095);
2158 static inline uint64_t rgw_rounded_objsize_kb(uint64_t bytes
)
2160 return ((bytes
+ 4095) & ~4095) / 1024;
2163 extern string
rgw_string_unquote(const string
& s
);
2164 extern void parse_csv_string(const string
& ival
, vector
<string
>& ovals
);
2165 extern int parse_key_value(string
& in_str
, string
& key
, string
& val
);
2166 extern int parse_key_value(string
& in_str
, const char *delim
, string
& key
, string
& val
);
2168 extern boost::optional
<std::pair
<boost::string_view
, boost::string_view
>>
2169 parse_key_value(const boost::string_view
& in_str
,
2170 const boost::string_view
& delim
);
2171 extern boost::optional
<std::pair
<boost::string_view
, boost::string_view
>>
2172 parse_key_value(const boost::string_view
& in_str
);
2176 extern int parse_time(const char *time_str
, real_time
*time
);
2177 extern bool parse_rfc2616(const char *s
, struct tm
*t
);
2178 extern bool parse_iso8601(const char *s
, struct tm
*t
, uint32_t *pns
= NULL
, bool extended_format
= true);
2179 extern string
rgw_trim_whitespace(const string
& src
);
2180 extern boost::string_view
rgw_trim_whitespace(const boost::string_view
& src
);
2181 extern string
rgw_trim_quotes(const string
& val
);
2183 extern void rgw_to_iso8601(const real_time
& t
, char *dest
, int buf_size
);
2184 extern void rgw_to_iso8601(const real_time
& t
, string
*dest
);
2186 /** Check if the req_state's user has the necessary permissions
2187 * to do the requested action */
2188 bool verify_user_permission(struct req_state
* const s
,
2189 RGWAccessControlPolicy
* const user_acl
,
2191 bool verify_user_permission(struct req_state
* const s
,
2193 bool verify_bucket_permission(
2194 struct req_state
* const s
,
2195 const rgw_bucket
& bucket
,
2196 RGWAccessControlPolicy
* const user_acl
,
2197 RGWAccessControlPolicy
* const bucket_acl
,
2198 const boost::optional
<rgw::IAM::Policy
>& bucket_policy
,
2200 bool verify_bucket_permission(struct req_state
* const s
, const uint64_t op
);
2201 bool verify_bucket_permission_no_policy(
2202 struct req_state
* const s
,
2203 RGWAccessControlPolicy
* const user_acl
,
2204 RGWAccessControlPolicy
* const bucket_acl
,
2206 bool verify_bucket_permission_no_policy(struct req_state
* const s
,
2208 extern bool verify_object_permission(
2209 struct req_state
* const s
,
2211 RGWAccessControlPolicy
* const user_acl
,
2212 RGWAccessControlPolicy
* const bucket_acl
,
2213 RGWAccessControlPolicy
* const object_acl
,
2214 const boost::optional
<rgw::IAM::Policy
>& bucket_policy
,
2216 extern bool verify_object_permission(struct req_state
*s
, uint64_t op
);
2217 extern bool verify_object_permission_no_policy(
2218 struct req_state
* const s
,
2219 RGWAccessControlPolicy
* const user_acl
,
2220 RGWAccessControlPolicy
* const bucket_acl
,
2221 RGWAccessControlPolicy
* const object_acl
,
2223 extern bool verify_object_permission_no_policy(struct req_state
*s
,
2225 /** Convert an input URL into a sane object name
2226 * by converting %-escaped strings into characters, etc*/
2227 extern void rgw_uri_escape_char(char c
, string
& dst
);
2228 extern std::string
url_decode(const boost::string_view
& src_str
,
2229 bool in_query
= false);
2230 extern void url_encode(const std::string
& src
,
2232 extern std::string
url_encode(const std::string
& src
);
2233 /* destination should be CEPH_CRYPTO_HMACSHA1_DIGESTSIZE bytes long */
2234 extern void calc_hmac_sha1(const char *key
, int key_len
,
2235 const char *msg
, int msg_len
, char *dest
);
2237 using sha1_digest_t
= \
2238 std::array
<char, CEPH_CRYPTO_HMACSHA1_DIGESTSIZE
>;
2240 static inline sha1_digest_t
2241 calc_hmac_sha1(const boost::string_view
& key
, const boost::string_view
& msg
) {
2243 calc_hmac_sha1(key
.data(), key
.size(), msg
.data(), msg
.size(), dest
.data());
2247 /* destination should be CEPH_CRYPTO_HMACSHA256_DIGESTSIZE bytes long */
2248 extern void calc_hmac_sha256(const char *key
, int key_len
,
2249 const char *msg
, int msg_len
,
2252 using sha256_digest_t
= \
2253 std::array
<unsigned char, CEPH_CRYPTO_HMACSHA256_DIGESTSIZE
>;
2255 static inline sha256_digest_t
2256 calc_hmac_sha256(const char *key
, const int key_len
,
2257 const char *msg
, const int msg_len
) {
2258 std::array
<unsigned char, CEPH_CRYPTO_HMACSHA256_DIGESTSIZE
> dest
;
2259 calc_hmac_sha256(key
, key_len
, msg
, msg_len
,
2260 reinterpret_cast<char*>(dest
.data()));
2264 static inline sha256_digest_t
2265 calc_hmac_sha256(const boost::string_view
& key
, const boost::string_view
& msg
) {
2266 std::array
<unsigned char, CEPH_CRYPTO_HMACSHA256_DIGESTSIZE
> dest
;
2267 calc_hmac_sha256(key
.data(), key
.size(),
2268 msg
.data(), msg
.size(),
2269 reinterpret_cast<char*>(dest
.data()));
2273 static inline sha256_digest_t
2274 calc_hmac_sha256(const std::vector
<unsigned char>& key
,
2275 const boost::string_view
& msg
) {
2276 std::array
<unsigned char, CEPH_CRYPTO_HMACSHA256_DIGESTSIZE
> dest
;
2277 calc_hmac_sha256(reinterpret_cast<const char*>(key
.data()), key
.size(),
2278 msg
.data(), msg
.size(),
2279 reinterpret_cast<char*>(dest
.data()));
2283 template<size_t KeyLenN
>
2284 static inline sha256_digest_t
2285 calc_hmac_sha256(const std::array
<unsigned char, KeyLenN
>& key
,
2286 const boost::string_view
& msg
) {
2287 std::array
<unsigned char, CEPH_CRYPTO_HMACSHA256_DIGESTSIZE
> dest
;
2288 calc_hmac_sha256(reinterpret_cast<const char*>(key
.data()), key
.size(),
2289 msg
.data(), msg
.size(),
2290 reinterpret_cast<char*>(dest
.data()));
2294 extern sha256_digest_t
calc_hash_sha256(const boost::string_view
& msg
);
2296 extern ceph::crypto::SHA256
* calc_hash_sha256_open_stream();
2297 extern void calc_hash_sha256_update_stream(ceph::crypto::SHA256
* hash
,
2300 extern std::string
calc_hash_sha256_close_stream(ceph::crypto::SHA256
** phash
);
2301 extern std::string
calc_hash_sha256_restart_stream(ceph::crypto::SHA256
** phash
);
2303 extern int rgw_parse_op_type_list(const string
& str
, uint32_t *perm
);
2306 constexpr uint32_t MATCH_POLICY_ACTION
= 0x01;
2307 constexpr uint32_t MATCH_POLICY_RESOURCE
= 0x02;
2308 constexpr uint32_t MATCH_POLICY_ARN
= 0x04;
2309 constexpr uint32_t MATCH_POLICY_STRING
= 0x08;
2312 int match(const std::string
& pattern
, const std::string
& input
, uint32_t flag
);