1 // -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
2 // vim: ts=8 sw=2 smarttab
5 * Ceph - scalable distributed file system
7 * Copyright (C) 2004-2009 Sage Weil <sage@newdream.net>
8 * Copyright (C) 2015 Yehuda Sadeh <yehuda@redhat.com>
10 * This is free software; you can redistribute it and/or
11 * modify it under the terms of the GNU Lesser General Public
12 * License version 2.1, as published by the Free Software
13 * Foundation. See file COPYING.
17 #ifndef CEPH_RGW_COMMON_H
18 #define CEPH_RGW_COMMON_H
22 #include <boost/algorithm/string.hpp>
23 #include <boost/utility/string_view.hpp>
25 #include "common/ceph_crypto.h"
28 #include "rgw_iam_policy.h"
29 #include "rgw_quota.h"
30 #include "rgw_string.h"
31 #include "common/async/yield_context.h"
32 #include "rgw_website.h"
33 #include "rgw_object_lock.h"
34 #include "cls/version/cls_version_types.h"
35 #include "cls/user/cls_user_types.h"
36 #include "cls/rgw/cls_rgw_types.h"
37 #include "include/rados/librados.hpp"
43 using ceph::crypto::MD5
;
46 #define RGW_ATTR_PREFIX "user.rgw."
48 #define RGW_HTTP_RGWX_ATTR_PREFIX "RGWX_ATTR_"
49 #define RGW_HTTP_RGWX_ATTR_PREFIX_OUT "Rgwx-Attr-"
51 #define RGW_AMZ_PREFIX "x-amz-"
52 #define RGW_AMZ_META_PREFIX RGW_AMZ_PREFIX "meta-"
53 #define RGW_AMZ_WEBSITE_REDIRECT_LOCATION RGW_AMZ_PREFIX "website-redirect-location"
54 #define RGW_AMZ_TAG_COUNT RGW_AMZ_PREFIX "tagging-count"
56 #define RGW_SYS_PARAM_PREFIX "rgwx-"
58 #define RGW_ATTR_ACL RGW_ATTR_PREFIX "acl"
59 #define RGW_ATTR_LC RGW_ATTR_PREFIX "lc"
60 #define RGW_ATTR_CORS RGW_ATTR_PREFIX "cors"
61 #define RGW_ATTR_ETAG RGW_ATTR_PREFIX "etag"
62 #define RGW_ATTR_BUCKETS RGW_ATTR_PREFIX "buckets"
63 #define RGW_ATTR_META_PREFIX RGW_ATTR_PREFIX RGW_AMZ_META_PREFIX
64 #define RGW_ATTR_CONTENT_TYPE RGW_ATTR_PREFIX "content_type"
65 #define RGW_ATTR_CACHE_CONTROL RGW_ATTR_PREFIX "cache_control"
66 #define RGW_ATTR_CONTENT_DISP RGW_ATTR_PREFIX "content_disposition"
67 #define RGW_ATTR_CONTENT_ENC RGW_ATTR_PREFIX "content_encoding"
68 #define RGW_ATTR_CONTENT_LANG RGW_ATTR_PREFIX "content_language"
69 #define RGW_ATTR_EXPIRES RGW_ATTR_PREFIX "expires"
70 #define RGW_ATTR_DELETE_AT RGW_ATTR_PREFIX "delete_at"
71 #define RGW_ATTR_ID_TAG RGW_ATTR_PREFIX "idtag"
72 #define RGW_ATTR_TAIL_TAG RGW_ATTR_PREFIX "tail_tag"
73 #define RGW_ATTR_SHADOW_OBJ RGW_ATTR_PREFIX "shadow_name"
74 #define RGW_ATTR_MANIFEST RGW_ATTR_PREFIX "manifest"
75 #define RGW_ATTR_USER_MANIFEST RGW_ATTR_PREFIX "user_manifest"
76 #define RGW_ATTR_AMZ_WEBSITE_REDIRECT_LOCATION RGW_ATTR_PREFIX RGW_AMZ_WEBSITE_REDIRECT_LOCATION
77 #define RGW_ATTR_SLO_MANIFEST RGW_ATTR_PREFIX "slo_manifest"
78 /* Information whether an object is SLO or not must be exposed to
79 * user through custom HTTP header named X-Static-Large-Object. */
80 #define RGW_ATTR_SLO_UINDICATOR RGW_ATTR_META_PREFIX "static-large-object"
81 #define RGW_ATTR_X_ROBOTS_TAG RGW_ATTR_PREFIX "x-robots-tag"
82 #define RGW_ATTR_STORAGE_CLASS RGW_ATTR_PREFIX "storage_class"
85 #define RGW_ATTR_OBJECT_LOCK RGW_ATTR_PREFIX "object-lock"
86 #define RGW_ATTR_OBJECT_RETENTION RGW_ATTR_PREFIX "object-retention"
87 #define RGW_ATTR_OBJECT_LEGAL_HOLD RGW_ATTR_PREFIX "object-legal-hold"
90 #define RGW_ATTR_PG_VER RGW_ATTR_PREFIX "pg_ver"
91 #define RGW_ATTR_SOURCE_ZONE RGW_ATTR_PREFIX "source_zone"
92 #define RGW_ATTR_TAGS RGW_ATTR_PREFIX RGW_AMZ_PREFIX "tagging"
94 #define RGW_ATTR_TEMPURL_KEY1 RGW_ATTR_META_PREFIX "temp-url-key"
95 #define RGW_ATTR_TEMPURL_KEY2 RGW_ATTR_META_PREFIX "temp-url-key-2"
97 /* Account/container quota of the Swift API. */
98 #define RGW_ATTR_QUOTA_NOBJS RGW_ATTR_META_PREFIX "quota-count"
99 #define RGW_ATTR_QUOTA_MSIZE RGW_ATTR_META_PREFIX "quota-bytes"
101 /* Static Web Site of Swift API. */
102 #define RGW_ATTR_WEB_INDEX RGW_ATTR_META_PREFIX "web-index"
103 #define RGW_ATTR_WEB_ERROR RGW_ATTR_META_PREFIX "web-error"
104 #define RGW_ATTR_WEB_LISTINGS RGW_ATTR_META_PREFIX "web-listings"
105 #define RGW_ATTR_WEB_LIST_CSS RGW_ATTR_META_PREFIX "web-listings-css"
106 #define RGW_ATTR_SUBDIR_MARKER RGW_ATTR_META_PREFIX "web-directory-type"
108 #define RGW_ATTR_OLH_PREFIX RGW_ATTR_PREFIX "olh."
110 #define RGW_ATTR_OLH_INFO RGW_ATTR_OLH_PREFIX "info"
111 #define RGW_ATTR_OLH_VER RGW_ATTR_OLH_PREFIX "ver"
112 #define RGW_ATTR_OLH_ID_TAG RGW_ATTR_OLH_PREFIX "idtag"
113 #define RGW_ATTR_OLH_PENDING_PREFIX RGW_ATTR_OLH_PREFIX "pending."
115 #define RGW_ATTR_COMPRESSION RGW_ATTR_PREFIX "compression"
117 #define RGW_ATTR_APPEND_PART_NUM RGW_ATTR_PREFIX "append_part_num"
120 #define RGW_ATTR_IAM_POLICY RGW_ATTR_PREFIX "iam-policy"
121 #define RGW_ATTR_USER_POLICY RGW_ATTR_PREFIX "user-policy"
123 /* RGW File Attributes */
124 #define RGW_ATTR_UNIX_KEY1 RGW_ATTR_PREFIX "unix-key1"
125 #define RGW_ATTR_UNIX1 RGW_ATTR_PREFIX "unix1"
127 #define RGW_ATTR_CRYPT_PREFIX RGW_ATTR_PREFIX "crypt."
128 #define RGW_ATTR_CRYPT_MODE RGW_ATTR_CRYPT_PREFIX "mode"
129 #define RGW_ATTR_CRYPT_KEYMD5 RGW_ATTR_CRYPT_PREFIX "keymd5"
130 #define RGW_ATTR_CRYPT_KEYID RGW_ATTR_CRYPT_PREFIX "keyid"
131 #define RGW_ATTR_CRYPT_KEYSEL RGW_ATTR_CRYPT_PREFIX "keysel"
133 #define RGW_BUCKETS_OBJ_SUFFIX ".buckets"
135 #define RGW_FORMAT_PLAIN 0
136 #define RGW_FORMAT_XML 1
137 #define RGW_FORMAT_JSON 2
138 #define RGW_FORMAT_HTML 3
140 #define RGW_CAP_READ 0x1
141 #define RGW_CAP_WRITE 0x2
142 #define RGW_CAP_ALL (RGW_CAP_READ | RGW_CAP_WRITE)
144 #define RGW_REST_SWIFT 0x1
145 #define RGW_REST_SWIFT_AUTH 0x2
146 #define RGW_REST_S3 0x4
147 #define RGW_REST_WEBSITE 0x8
148 #define RGW_REST_STS 0x10
150 #define RGW_SUSPENDED_USER_AUID (uint64_t)-2
152 #define RGW_OP_TYPE_READ 0x01
153 #define RGW_OP_TYPE_WRITE 0x02
154 #define RGW_OP_TYPE_DELETE 0x04
156 #define RGW_OP_TYPE_MODIFY (RGW_OP_TYPE_WRITE | RGW_OP_TYPE_DELETE)
157 #define RGW_OP_TYPE_ALL (RGW_OP_TYPE_READ | RGW_OP_TYPE_WRITE | RGW_OP_TYPE_DELETE)
159 #define RGW_DEFAULT_MAX_BUCKETS 1000
161 #define RGW_DEFER_TO_BUCKET_ACLS_RECURSE 1
162 #define RGW_DEFER_TO_BUCKET_ACLS_FULL_CONTROL 2
164 #define STATUS_CREATED 1900
165 #define STATUS_ACCEPTED 1901
166 #define STATUS_NO_CONTENT 1902
167 #define STATUS_PARTIAL_CONTENT 1903
168 #define STATUS_REDIRECT 1904
169 #define STATUS_NO_APPLY 1905
170 #define STATUS_APPLIED 1906
172 #define ERR_INVALID_BUCKET_NAME 2000
173 #define ERR_INVALID_OBJECT_NAME 2001
174 #define ERR_NO_SUCH_BUCKET 2002
175 #define ERR_METHOD_NOT_ALLOWED 2003
176 #define ERR_INVALID_DIGEST 2004
177 #define ERR_BAD_DIGEST 2005
178 #define ERR_UNRESOLVABLE_EMAIL 2006
179 #define ERR_INVALID_PART 2007
180 #define ERR_INVALID_PART_ORDER 2008
181 #define ERR_NO_SUCH_UPLOAD 2009
182 #define ERR_REQUEST_TIMEOUT 2010
183 #define ERR_LENGTH_REQUIRED 2011
184 #define ERR_REQUEST_TIME_SKEWED 2012
185 #define ERR_BUCKET_EXISTS 2013
186 #define ERR_BAD_URL 2014
187 #define ERR_PRECONDITION_FAILED 2015
188 #define ERR_NOT_MODIFIED 2016
189 #define ERR_INVALID_UTF8 2017
190 #define ERR_UNPROCESSABLE_ENTITY 2018
191 #define ERR_TOO_LARGE 2019
192 #define ERR_TOO_MANY_BUCKETS 2020
193 #define ERR_INVALID_REQUEST 2021
194 #define ERR_TOO_SMALL 2022
195 #define ERR_NOT_FOUND 2023
196 #define ERR_PERMANENT_REDIRECT 2024
197 #define ERR_LOCKED 2025
198 #define ERR_QUOTA_EXCEEDED 2026
199 #define ERR_SIGNATURE_NO_MATCH 2027
200 #define ERR_INVALID_ACCESS_KEY 2028
201 #define ERR_MALFORMED_XML 2029
202 #define ERR_USER_EXIST 2030
203 #define ERR_NOT_SLO_MANIFEST 2031
204 #define ERR_EMAIL_EXIST 2032
205 #define ERR_KEY_EXIST 2033
206 #define ERR_INVALID_SECRET_KEY 2034
207 #define ERR_INVALID_KEY_TYPE 2035
208 #define ERR_INVALID_CAP 2036
209 #define ERR_INVALID_TENANT_NAME 2037
210 #define ERR_WEBSITE_REDIRECT 2038
211 #define ERR_NO_SUCH_WEBSITE_CONFIGURATION 2039
212 #define ERR_AMZ_CONTENT_SHA256_MISMATCH 2040
213 #define ERR_NO_SUCH_LC 2041
214 #define ERR_NO_SUCH_USER 2042
215 #define ERR_NO_SUCH_SUBUSER 2043
216 #define ERR_MFA_REQUIRED 2044
217 #define ERR_NO_SUCH_CORS_CONFIGURATION 2045
218 #define ERR_NO_SUCH_OBJECT_LOCK_CONFIGURATION 2046
219 #define ERR_INVALID_RETENTION_PERIOD 2047
220 #define ERR_USER_SUSPENDED 2100
221 #define ERR_INTERNAL_ERROR 2200
222 #define ERR_NOT_IMPLEMENTED 2201
223 #define ERR_SERVICE_UNAVAILABLE 2202
224 #define ERR_ROLE_EXISTS 2203
225 #define ERR_MALFORMED_DOC 2204
226 #define ERR_NO_ROLE_FOUND 2205
227 #define ERR_DELETE_CONFLICT 2206
228 #define ERR_NO_SUCH_BUCKET_POLICY 2207
229 #define ERR_INVALID_LOCATION_CONSTRAINT 2208
230 #define ERR_TAG_CONFLICT 2209
231 #define ERR_INVALID_TAG 2210
232 #define ERR_ZERO_IN_URL 2211
233 #define ERR_MALFORMED_ACL_ERROR 2212
234 #define ERR_ZONEGROUP_DEFAULT_PLACEMENT_MISCONFIGURATION 2213
235 #define ERR_INVALID_ENCRYPTION_ALGORITHM 2214
236 #define ERR_INVALID_CORS_RULES_ERROR 2215
237 #define ERR_NO_CORS_FOUND 2216
238 #define ERR_INVALID_WEBSITE_ROUTING_RULES_ERROR 2217
239 #define ERR_RATE_LIMITED 2218
240 #define ERR_POSITION_NOT_EQUAL_TO_LENGTH 2219
241 #define ERR_OBJECT_NOT_APPENDABLE 2220
242 #define ERR_INVALID_BUCKET_STATE 2221
244 #define ERR_BUSY_RESHARDING 2300
245 #define ERR_NO_SUCH_ENTITY 2301
248 #define ERR_PACKED_POLICY_TOO_LARGE 2400
249 #define ERR_INVALID_IDENTITY_TOKEN 2401
252 #define UINT32_MAX (0xffffffffu)
257 typedef void *RGWAccessHandle
;
259 /* size should be the required string size + 1 */
260 int gen_rand_base64(CephContext
*cct
, char *dest
, int size
);
261 void gen_rand_alphanumeric(CephContext
*cct
, char *dest
, int size
);
262 void gen_rand_alphanumeric_lower(CephContext
*cct
, char *dest
, int size
);
263 void gen_rand_alphanumeric_upper(CephContext
*cct
, char *dest
, int size
);
264 void gen_rand_alphanumeric_no_underscore(CephContext
*cct
, char *dest
, int size
);
265 void gen_rand_alphanumeric_plain(CephContext
*cct
, char *dest
, int size
);
266 void gen_rand_alphanumeric_lower(CephContext
*cct
, string
*str
, int length
);
268 enum RGWIntentEvent
{
278 /** Store error returns for output at a different point in the program */
282 bool is_clear() const;
284 friend std::ostream
& operator<<(std::ostream
& oss
, const rgw_err
&err
);
288 std::string err_code
;
294 /* Helper class used for RGWHTTPArgs parsing */
297 const std::string str
;
301 explicit NameVal(const std::string
& nv
) : str(nv
) {}
305 std::string
& get_name() { return name
; }
306 std::string
& get_val() { return val
; }
309 /** Stores the XML arguments associated with the HTTP request in req_state*/
311 std::string str
, empty_str
;
312 std::map
<std::string
, std::string
> val_map
;
313 std::map
<std::string
, std::string
> sys_val_map
;
314 std::map
<std::string
, std::string
> sub_resources
;
315 bool has_resp_modifier
= false;
316 bool admin_subresource_added
= false;
318 RGWHTTPArgs() = default;
319 explicit RGWHTTPArgs(const std::string
& s
) {
324 /** Set the arguments; as received */
325 void set(const std::string
& s
) {
326 has_resp_modifier
= false;
328 sub_resources
.clear();
331 /** parse the received arguments */
333 void append(const std::string
& name
, const string
& val
);
334 /** Get the value for a specific argument parameter */
335 const string
& get(const std::string
& name
, bool *exists
= NULL
) const;
336 boost::optional
<const std::string
&>
337 get_optional(const std::string
& name
) const;
338 int get_bool(const std::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
);
341 int get_int(const char *name
, int *val
, int def_val
);
343 /** Get the value for specific system argument parameter */
344 std::string
sys_get(const std::string
& name
, bool *exists
= nullptr) const;
346 /** see if a parameter is contained in this RGWHTTPArgs */
347 bool exists(const char *name
) const {
348 return (val_map
.find(name
) != std::end(val_map
));
350 bool sub_resource_exists(const char *name
) const {
351 return (sub_resources
.find(name
) != std::end(sub_resources
));
353 std::map
<std::string
, std::string
>& get_params() {
356 const std::map
<std::string
, std::string
>& get_sub_resources() const {
357 return sub_resources
;
359 unsigned get_num_params() const {
360 return val_map
.size();
362 bool has_response_modifier() const {
363 return has_resp_modifier
;
365 void set_system() { /* make all system params visible */
366 std::map
<std::string
, std::string
>::iterator iter
;
367 for (iter
= sys_val_map
.begin(); iter
!= sys_val_map
.end(); ++iter
) {
368 val_map
[iter
->first
] = iter
->second
;
371 const std::string
& get_str() {
376 const char *rgw_conf_get(const map
<string
, string
, ltstr_nocase
>& conf_map
, const char *name
, const char *def_val
);
377 int rgw_conf_get_int(const map
<string
, string
, ltstr_nocase
>& conf_map
, const char *name
, int def_val
);
378 bool rgw_conf_get_bool(const map
<string
, string
, ltstr_nocase
>& conf_map
, const char *name
, bool def_val
);
385 int enable_usage_log
;
386 uint8_t defer_to_bucket_acls
;
387 void init(CephContext
*cct
);
392 defer_to_bucket_acls(0) {
397 std::map
<string
, string
, ltstr_nocase
> env_map
;
400 void init(CephContext
*cct
);
401 void init(CephContext
*cct
, char **envp
);
402 void set(std::string name
, std::string val
);
403 const char *get(const char *name
, const char *def_val
= nullptr) const;
404 int get_int(const char *name
, int def_val
= 0) const;
405 bool get_bool(const char *name
, bool def_val
= 0);
406 size_t get_size(const char *name
, size_t def_val
= 0) const;
407 bool exists(const char *name
) const;
408 bool exists_prefix(const char *prefix
) const;
409 void remove(const char *name
);
410 const std::map
<string
, string
, ltstr_nocase
>& get_map() const { return env_map
; }
411 int get_enable_ops_log() const {
412 return conf
.enable_ops_log
;
415 int get_enable_usage_log() const {
416 return conf
.enable_usage_log
;
419 int get_defer_to_bucket_acls() const {
420 return conf
.defer_to_bucket_acls
;
424 // return true if the connection is secure. this either means that the
425 // connection arrived via ssl, or was forwarded as https by a trusted proxy
426 bool rgw_transport_is_secure(CephContext
*cct
, const RGWEnv
& env
);
445 RGW_OP_GET_BUCKET_LOGGING
,
446 RGW_OP_GET_BUCKET_LOCATION
,
447 RGW_OP_GET_BUCKET_VERSIONING
,
448 RGW_OP_SET_BUCKET_VERSIONING
,
449 RGW_OP_GET_BUCKET_WEBSITE
,
450 RGW_OP_SET_BUCKET_WEBSITE
,
452 RGW_OP_CREATE_BUCKET
,
453 RGW_OP_DELETE_BUCKET
,
457 RGW_OP_PUT_METADATA_ACCOUNT
,
458 RGW_OP_PUT_METADATA_BUCKET
,
459 RGW_OP_PUT_METADATA_OBJECT
,
469 RGW_OP_GET_REQUEST_PAYMENT
,
470 RGW_OP_SET_REQUEST_PAYMENT
,
471 RGW_OP_INIT_MULTIPART
,
472 RGW_OP_COMPLETE_MULTIPART
,
473 RGW_OP_ABORT_MULTIPART
,
474 RGW_OP_LIST_MULTIPART
,
475 RGW_OP_LIST_BUCKET_MULTIPARTS
,
476 RGW_OP_DELETE_MULTI_OBJ
,
479 RGW_OP_GET_CROSS_DOMAIN_POLICY
,
480 RGW_OP_GET_HEALTH_CHECK
,
487 RGW_OP_PUT_ROLE_POLICY
,
488 RGW_OP_GET_ROLE_POLICY
,
489 RGW_OP_LIST_ROLE_POLICIES
,
490 RGW_OP_DELETE_ROLE_POLICY
,
491 RGW_OP_PUT_BUCKET_POLICY
,
492 RGW_OP_GET_BUCKET_POLICY
,
493 RGW_OP_DELETE_BUCKET_POLICY
,
494 RGW_OP_PUT_OBJ_TAGGING
,
495 RGW_OP_GET_OBJ_TAGGING
,
496 RGW_OP_DELETE_OBJ_TAGGING
,
500 RGW_OP_PUT_USER_POLICY
,
501 RGW_OP_GET_USER_POLICY
,
502 RGW_OP_LIST_USER_POLICIES
,
503 RGW_OP_DELETE_USER_POLICY
,
504 RGW_OP_PUT_BUCKET_OBJ_LOCK
,
505 RGW_OP_GET_BUCKET_OBJ_LOCK
,
506 RGW_OP_PUT_OBJ_RETENTION
,
507 RGW_OP_GET_OBJ_RETENTION
,
508 RGW_OP_PUT_OBJ_LEGAL_HOLD
,
509 RGW_OP_GET_OBJ_LEGAL_HOLD
,
511 RGW_OP_ADMIN_SET_METADATA
,
512 RGW_OP_GET_OBJ_LAYOUT
,
514 RGW_OP_METADATA_SEARCH
,
515 RGW_OP_CONFIG_BUCKET_META_SEARCH
,
516 RGW_OP_GET_BUCKET_META_SEARCH
,
517 RGW_OP_DEL_BUCKET_META_SEARCH
,
520 RGW_STS_GET_SESSION_TOKEN
,
521 RGW_STS_ASSUME_ROLE_WEB_IDENTITY
,
523 RGW_OP_PUBSUB_TOPIC_CREATE
,
524 RGW_OP_PUBSUB_TOPICS_LIST
,
525 RGW_OP_PUBSUB_TOPIC_GET
,
526 RGW_OP_PUBSUB_TOPIC_DELETE
,
527 RGW_OP_PUBSUB_SUB_CREATE
,
528 RGW_OP_PUBSUB_SUB_GET
,
529 RGW_OP_PUBSUB_SUB_DELETE
,
530 RGW_OP_PUBSUB_SUB_PULL
,
531 RGW_OP_PUBSUB_SUB_ACK
,
532 RGW_OP_PUBSUB_NOTIF_CREATE
,
533 RGW_OP_PUBSUB_NOTIF_DELETE
,
534 RGW_OP_PUBSUB_NOTIF_LIST
,
537 class RGWAccessControlPolicy
;
540 struct RGWAccessKey
{
541 string id
; // AccessKey
542 string key
; // SecretKey
546 RGWAccessKey(std::string _id
, std::string _key
)
547 : id(std::move(_id
)), key(std::move(_key
)) {}
549 void encode(bufferlist
& bl
) const {
550 ENCODE_START(2, 2, bl
);
557 void decode(bufferlist::const_iterator
& bl
) {
558 DECODE_START_LEGACY_COMPAT_LEN_32(2, 2, 2, bl
);
564 void dump(Formatter
*f
) const;
565 void dump_plain(Formatter
*f
) const;
566 void dump(Formatter
*f
, const string
& user
, bool swift
) const;
567 static void generate_test_instances(list
<RGWAccessKey
*>& o
);
569 void decode_json(JSONObj
*obj
);
570 void decode_json(JSONObj
*obj
, bool swift
);
572 WRITE_CLASS_ENCODER(RGWAccessKey
)
578 RGWSubUser() : perm_mask(0) {}
579 void encode(bufferlist
& bl
) const {
580 ENCODE_START(2, 2, bl
);
582 encode(perm_mask
, bl
);
586 void decode(bufferlist::const_iterator
& bl
) {
587 DECODE_START_LEGACY_COMPAT_LEN_32(2, 2, 2, bl
);
589 decode(perm_mask
, bl
);
592 void dump(Formatter
*f
) const;
593 void dump(Formatter
*f
, const string
& user
) const;
594 static void generate_test_instances(list
<RGWSubUser
*>& o
);
596 void decode_json(JSONObj
*obj
);
598 WRITE_CLASS_ENCODER(RGWSubUser
)
602 map
<string
, uint32_t> caps
;
604 int get_cap(const string
& cap
, string
& type
, uint32_t *perm
);
605 int add_cap(const string
& cap
);
606 int remove_cap(const string
& cap
);
608 static int parse_cap_perm(const string
& str
, uint32_t *perm
);
609 int add_from_string(const string
& str
);
610 int remove_from_string(const string
& str
);
612 void encode(bufferlist
& bl
) const {
613 ENCODE_START(1, 1, bl
);
617 void decode(bufferlist::const_iterator
& bl
) {
622 int check_cap(const string
& cap
, uint32_t perm
);
623 bool is_valid_cap_type(const string
& tp
);
624 void dump(Formatter
*f
) const;
625 void dump(Formatter
*f
, const char *name
) const;
627 void decode_json(JSONObj
*obj
);
629 WRITE_CLASS_ENCODER(RGWUserCaps
)
631 void encode_json(const char *name
, const obj_version
& v
, Formatter
*f
);
632 void encode_json(const char *name
, const RGWUserCaps
& val
, Formatter
*f
);
634 void decode_json_obj(obj_version
& v
, JSONObj
*obj
);
648 static string RGW_STORAGE_CLASS_STANDARD
= "STANDARD";
650 struct rgw_placement_rule
{
652 std::string storage_class
;
654 rgw_placement_rule() {}
655 rgw_placement_rule(const string
& _n
, const string
& _sc
) : name(_n
), storage_class(_sc
) {}
656 rgw_placement_rule(const rgw_placement_rule
& _r
, const string
& _sc
) : name(_r
.name
) {
660 storage_class
= _r
.storage_class
;
665 return name
.empty() && storage_class
.empty();
668 void inherit_from(const rgw_placement_rule
& r
) {
672 if (storage_class
.empty()) {
673 storage_class
= r
.storage_class
;
679 storage_class
.clear();
682 void init(const string
& n
, const string
& c
) {
687 static const string
& get_canonical_storage_class(const string
& storage_class
) {
688 if (storage_class
.empty()) {
689 return RGW_STORAGE_CLASS_STANDARD
;
691 return storage_class
;
694 const string
& get_storage_class() const {
695 return get_canonical_storage_class(storage_class
);
698 int compare(const rgw_placement_rule
& r
) const {
699 int c
= name
.compare(r
.name
);
703 return get_storage_class().compare(r
.get_storage_class());
706 bool operator==(const rgw_placement_rule
& r
) const {
707 return (name
== r
.name
&&
708 get_storage_class() == r
.get_storage_class());
711 bool operator!=(const rgw_placement_rule
& r
) const {
712 return !(*this == r
);
715 void encode(bufferlist
& bl
) const {
716 /* no ENCODE_START/END due to backward compatibility */
717 std::string s
= to_str();
721 void decode(bufferlist::const_iterator
& bl
) {
727 std::string
to_str() const {
728 if (standard_storage_class()) {
731 return to_str_explicit();
734 std::string
to_str_explicit() const {
735 return name
+ "/" + storage_class
;
738 void from_str(const std::string
& s
) {
739 size_t pos
= s
.find("/");
740 if (pos
== std::string::npos
) {
742 storage_class
.clear();
745 name
= s
.substr(0, pos
);
746 storage_class
= s
.substr(pos
+ 1);
749 bool standard_storage_class() const {
750 return storage_class
.empty() || storage_class
== RGW_STORAGE_CLASS_STANDARD
;
753 WRITE_CLASS_ENCODER(rgw_placement_rule
)
755 void encode_json(const char *name
, const rgw_placement_rule
& val
, ceph::Formatter
*f
);
756 void decode_json_obj(rgw_placement_rule
& v
, JSONObj
*obj
);
758 inline ostream
& operator<<(ostream
& out
, const rgw_placement_rule
& rule
) {
759 return out
<< rule
.to_str();
766 map
<string
, RGWAccessKey
> access_keys
;
767 map
<string
, RGWAccessKey
> swift_keys
;
768 map
<string
, RGWSubUser
> subusers
;
775 rgw_placement_rule default_placement
;
776 list
<string
> placement_tags
;
777 RGWQuotaInfo bucket_quota
;
778 map
<int, string
> temp_url_keys
;
779 RGWQuotaInfo user_quota
;
782 string assumed_role_arn
;
786 max_buckets(RGW_DEFAULT_MAX_BUCKETS
),
787 op_mask(RGW_OP_TYPE_ALL
),
793 RGWAccessKey
* get_key(const string
& access_key
) {
794 if (access_keys
.empty())
797 auto k
= access_keys
.find(access_key
);
798 if (k
== access_keys
.end())
804 void encode(bufferlist
& bl
) const {
805 ENCODE_START(21, 9, bl
);
806 encode((uint64_t)0, bl
); // old auid
809 if (!access_keys
.empty()) {
810 map
<string
, RGWAccessKey
>::const_iterator iter
= access_keys
.begin();
811 const RGWAccessKey
& k
= iter
->second
;
815 encode(access_key
, bl
);
816 encode(secret_key
, bl
);
817 encode(display_name
, bl
);
818 encode(user_email
, bl
);
821 if (!swift_keys
.empty()) {
822 map
<string
, RGWAccessKey
>::const_iterator iter
= swift_keys
.begin();
823 const RGWAccessKey
& k
= iter
->second
;
827 encode(swift_name
, bl
);
828 encode(swift_key
, bl
);
829 encode(user_id
.id
, bl
);
830 encode(access_keys
, bl
);
831 encode(subusers
, bl
);
832 encode(suspended
, bl
);
833 encode(swift_keys
, bl
);
834 encode(max_buckets
, bl
);
838 encode(default_placement
, bl
);
839 encode(placement_tags
, bl
);
840 encode(bucket_quota
, bl
);
841 encode(temp_url_keys
, bl
);
842 encode(user_quota
, bl
);
843 encode(user_id
.tenant
, bl
);
847 encode(assumed_role_arn
, bl
);
850 void decode(bufferlist::const_iterator
& bl
) {
851 DECODE_START_LEGACY_COMPAT_LEN_32(20, 9, 9, bl
);
854 decode(old_auid
, bl
);
858 decode(access_key
, bl
);
859 decode(secret_key
, bl
);
864 access_keys
[access_key
] = k
;
866 decode(display_name
, bl
);
867 decode(user_email
, bl
);
868 /* We populate swift_keys map later nowadays, but we have to decode. */
871 if (struct_v
>= 3) decode(swift_name
, bl
);
872 if (struct_v
>= 4) decode(swift_key
, bl
);
874 decode(user_id
.id
, bl
);
876 user_id
.id
= access_key
;
878 decode(access_keys
, bl
);
879 decode(subusers
, bl
);
883 decode(suspended
, bl
);
886 decode(swift_keys
, bl
);
888 if (struct_v
>= 10) {
889 decode(max_buckets
, bl
);
891 max_buckets
= RGW_DEFAULT_MAX_BUCKETS
;
893 if (struct_v
>= 11) {
896 if (struct_v
>= 12) {
899 op_mask
= RGW_OP_TYPE_ALL
;
901 if (struct_v
>= 13) {
903 decode(default_placement
, bl
);
904 decode(placement_tags
, bl
); /* tags of allowed placement rules */
906 if (struct_v
>= 14) {
907 decode(bucket_quota
, bl
);
909 if (struct_v
>= 15) {
910 decode(temp_url_keys
, bl
);
912 if (struct_v
>= 16) {
913 decode(user_quota
, bl
);
915 if (struct_v
>= 17) {
916 decode(user_id
.tenant
, bl
);
918 user_id
.tenant
.clear();
920 if (struct_v
>= 18) {
923 if (struct_v
>= 19) {
926 if (struct_v
>= 20) {
929 if (struct_v
>= 21) {
930 decode(assumed_role_arn
, bl
);
934 void dump(Formatter
*f
) const;
935 static void generate_test_instances(list
<RGWUserInfo
*>& o
);
937 void decode_json(JSONObj
*obj
);
939 WRITE_CLASS_ENCODER(RGWUserInfo
)
945 rgw_pool() = default;
946 rgw_pool(const rgw_pool
& _p
) : name(_p
.name
), ns(_p
.ns
) {}
947 rgw_pool(rgw_pool
&&) = default;
948 rgw_pool(const string
& _s
) {
951 rgw_pool(const string
& _name
, const string
& _ns
) : name(_name
), ns(_ns
) {}
953 string
to_str() const;
954 void from_str(const string
& s
);
956 void init(const string
& _s
) {
964 int compare(const rgw_pool
& p
) const {
965 int r
= name
.compare(p
.name
);
969 return ns
.compare(p
.ns
);
972 void encode(bufferlist
& bl
) const {
973 ENCODE_START(10, 10, bl
);
979 void decode_from_bucket(bufferlist::const_iterator
& bl
);
981 void decode(bufferlist::const_iterator
& bl
) {
982 DECODE_START_LEGACY_COMPAT_LEN(10, 3, 3, bl
);
989 * note that rgw_pool can be used where rgw_bucket was used before
990 * therefore we inherit rgw_bucket's old versions. However, we only
991 * need the first field from rgw_bucket. unless we add more fields
992 * in which case we'll need to look at struct_v, and check the actual
993 * version. Anything older than 10 needs to be treated as old rgw_bucket
1003 rgw_pool
& operator=(const rgw_pool
&) = default;
1005 bool operator==(const rgw_pool
& p
) const {
1006 return (compare(p
) == 0);
1008 bool operator!=(const rgw_pool
& p
) const {
1009 return !(*this == p
);
1011 bool operator<(const rgw_pool
& p
) const {
1012 int r
= name
.compare(p
.name
);
1014 return (ns
.compare(p
.ns
) < 0);
1019 WRITE_CLASS_ENCODER(rgw_pool
)
1021 struct rgw_data_placement_target
{
1023 rgw_pool data_extra_pool
;
1024 rgw_pool index_pool
;
1026 rgw_data_placement_target() = default;
1027 rgw_data_placement_target(const rgw_data_placement_target
&) = default;
1028 rgw_data_placement_target(rgw_data_placement_target
&&) = default;
1030 rgw_data_placement_target(const rgw_pool
& data_pool
,
1031 const rgw_pool
& data_extra_pool
,
1032 const rgw_pool
& index_pool
)
1033 : data_pool(data_pool
),
1034 data_extra_pool(data_extra_pool
),
1035 index_pool(index_pool
) {
1038 rgw_data_placement_target
&
1039 operator=(const rgw_data_placement_target
&) = default;
1041 const rgw_pool
& get_data_extra_pool() const {
1042 if (data_extra_pool
.empty()) {
1045 return data_extra_pool
;
1048 int compare(const rgw_data_placement_target
& t
) {
1049 int c
= data_pool
.compare(t
.data_pool
);
1053 c
= data_extra_pool
.compare(t
.data_extra_pool
);
1057 return index_pool
.compare(t
.index_pool
);
1060 void dump(Formatter
*f
) const;
1061 void decode_json(JSONObj
*obj
);
1064 inline ostream
& operator<<(ostream
& out
, const rgw_pool
& p
) {
1069 struct rgw_raw_obj
{
1075 rgw_raw_obj(const rgw_pool
& _pool
, const std::string
& _oid
) {
1078 rgw_raw_obj(const rgw_pool
& _pool
, const std::string
& _oid
, const string
& _loc
) : loc(_loc
) {
1082 void init(const rgw_pool
& _pool
, const std::string
& _oid
) {
1087 bool empty() const {
1091 void encode(bufferlist
& bl
) const {
1092 ENCODE_START(6, 6, bl
);
1099 void decode_from_rgw_obj(bufferlist::const_iterator
& bl
);
1101 void decode(bufferlist::const_iterator
& bl
) {
1102 unsigned ofs
= bl
.get_off();
1103 DECODE_START(6, bl
);
1106 * this object was encoded as rgw_obj, prior to rgw_raw_obj been split out of it,
1107 * let's decode it as rgw_obj and convert it
1110 decode_from_rgw_obj(bl
);
1119 bool operator<(const rgw_raw_obj
& o
) const {
1120 int r
= pool
.compare(o
.pool
);
1122 r
= oid
.compare(o
.oid
);
1124 r
= loc
.compare(o
.loc
);
1130 bool operator==(const rgw_raw_obj
& o
) const {
1131 return (pool
== o
.pool
&& oid
== o
.oid
&& loc
== o
.loc
);
1134 void dump(Formatter
*f
) const;
1135 void decode_json(JSONObj
*obj
);
1137 WRITE_CLASS_ENCODER(rgw_raw_obj
)
1139 inline ostream
& operator<<(ostream
& out
, const rgw_raw_obj
& o
) {
1140 out
<< o
.pool
<< ":" << o
.oid
;
1148 std::string bucket_id
;
1149 rgw_data_placement_target explicit_placement
;
1152 * runtime in-memory only info. If not empty, points to the bucket instance object
1156 // cppcheck-suppress noExplicitConstructor
1157 explicit rgw_bucket(const rgw_user
& u
, const cls_user_bucket
& b
) :
1161 bucket_id(b
.bucket_id
),
1162 explicit_placement(b
.explicit_placement
.data_pool
,
1163 b
.explicit_placement
.data_extra_pool
,
1164 b
.explicit_placement
.index_pool
) {}
1165 rgw_bucket(const rgw_bucket
&) = default;
1166 rgw_bucket(rgw_bucket
&&) = default;
1168 void convert(cls_user_bucket
*b
) const {
1171 b
->bucket_id
= bucket_id
;
1172 b
->explicit_placement
.data_pool
= explicit_placement
.data_pool
.to_str();
1173 b
->explicit_placement
.data_extra_pool
= explicit_placement
.data_extra_pool
.to_str();
1174 b
->explicit_placement
.index_pool
= explicit_placement
.index_pool
.to_str();
1177 void encode(bufferlist
& bl
) const {
1178 ENCODE_START(10, 10, bl
);
1181 encode(bucket_id
, bl
);
1183 bool encode_explicit
= !explicit_placement
.data_pool
.empty();
1184 encode(encode_explicit
, bl
);
1185 if (encode_explicit
) {
1186 encode(explicit_placement
.data_pool
, bl
);
1187 encode(explicit_placement
.data_extra_pool
, bl
);
1188 encode(explicit_placement
.index_pool
, bl
);
1192 void decode(bufferlist::const_iterator
& bl
) {
1193 DECODE_START_LEGACY_COMPAT_LEN(10, 3, 3, bl
);
1195 if (struct_v
< 10) {
1196 decode(explicit_placement
.data_pool
.name
, bl
);
1198 if (struct_v
>= 2) {
1200 if (struct_v
<= 3) {
1204 snprintf(buf
, sizeof(buf
), "%" PRIu64
, id
);
1207 decode(bucket_id
, bl
);
1210 if (struct_v
< 10) {
1211 if (struct_v
>= 5) {
1212 decode(explicit_placement
.index_pool
.name
, bl
);
1214 explicit_placement
.index_pool
= explicit_placement
.data_pool
;
1216 if (struct_v
>= 7) {
1217 decode(explicit_placement
.data_extra_pool
.name
, bl
);
1220 if (struct_v
>= 8) {
1223 if (struct_v
>= 10) {
1224 bool decode_explicit
= !explicit_placement
.data_pool
.empty();
1225 decode(decode_explicit
, bl
);
1226 if (decode_explicit
) {
1227 decode(explicit_placement
.data_pool
, bl
);
1228 decode(explicit_placement
.data_extra_pool
, bl
);
1229 decode(explicit_placement
.index_pool
, bl
);
1235 void update_bucket_id(const string
& new_bucket_id
) {
1236 bucket_id
= new_bucket_id
;
1240 // format a key for the bucket/instance. pass delim=0 to skip a field
1241 std::string
get_key(char tenant_delim
= '/',
1242 char id_delim
= ':',
1243 size_t reserve
= 0) const;
1245 const rgw_pool
& get_data_extra_pool() const {
1246 return explicit_placement
.get_data_extra_pool();
1249 void dump(Formatter
*f
) const;
1250 void decode_json(JSONObj
*obj
);
1251 static void generate_test_instances(list
<rgw_bucket
*>& o
);
1253 rgw_bucket
& operator=(const rgw_bucket
&) = default;
1255 bool operator<(const rgw_bucket
& b
) const {
1256 if (tenant
== b
.tenant
) {
1257 return name
< b
.name
;
1259 return tenant
< b
.tenant
;
1263 bool operator==(const rgw_bucket
& b
) const {
1264 return (tenant
== b
.tenant
) && (name
== b
.name
) && \
1265 (bucket_id
== b
.bucket_id
);
1268 WRITE_CLASS_ENCODER(rgw_bucket
)
1270 inline ostream
& operator<<(ostream
& out
, const rgw_bucket
&b
) {
1271 out
<< b
.name
<< "[" << b
.marker
<< "]";
1275 struct rgw_bucket_shard
{
1279 rgw_bucket_shard() : shard_id(-1) {}
1280 rgw_bucket_shard(const rgw_bucket
& _b
, int _sid
) : bucket(_b
), shard_id(_sid
) {}
1282 std::string
get_key(char tenant_delim
= '/', char id_delim
= ':',
1283 char shard_delim
= ':') const;
1285 bool operator<(const rgw_bucket_shard
& b
) const {
1286 if (bucket
< b
.bucket
) {
1289 if (b
.bucket
< bucket
) {
1292 return shard_id
< b
.shard_id
;
1297 struct RGWObjVersionTracker
{
1298 obj_version read_version
;
1299 obj_version write_version
;
1301 obj_version
*version_for_read() {
1302 return &read_version
;
1305 obj_version
*version_for_write() {
1306 if (write_version
.ver
== 0)
1309 return &write_version
;
1312 obj_version
*version_for_check() {
1313 if (read_version
.ver
== 0)
1316 return &read_version
;
1319 void prepare_op_for_read(librados::ObjectReadOperation
*op
);
1320 void prepare_op_for_write(librados::ObjectWriteOperation
*op
);
1322 void apply_write() {
1323 read_version
= write_version
;
1324 write_version
= obj_version();
1328 read_version
= obj_version();
1329 write_version
= obj_version();
1332 void generate_new_write_ver(CephContext
*cct
);
1335 inline ostream
& operator<<(ostream
& out
, const obj_version
&v
)
1337 out
<< v
.tag
<< ":" << v
.ver
;
1341 inline ostream
& operator<<(ostream
& out
, const RGWObjVersionTracker
&ot
)
1343 out
<< "{r=" << ot
.read_version
<< ",w=" << ot
.write_version
<< "}";
1347 enum RGWBucketFlags
{
1348 BUCKET_SUSPENDED
= 0x1,
1349 BUCKET_VERSIONED
= 0x2,
1350 BUCKET_VERSIONS_SUSPENDED
= 0x4,
1351 BUCKET_DATASYNC_DISABLED
= 0X8,
1352 BUCKET_MFA_ENABLED
= 0X10,
1353 BUCKET_OBJ_LOCK_ENABLED
= 0X20,
1356 enum RGWBucketIndexType
{
1357 RGWBIType_Normal
= 0,
1358 RGWBIType_Indexless
= 1,
1361 inline ostream
& operator<<(ostream
& out
, const RGWBucketIndexType
&index_type
)
1363 switch (index_type
) {
1364 case RGWBIType_Normal
:
1365 return out
<< "Normal";
1366 case RGWBIType_Indexless
:
1367 return out
<< "Indexless";
1369 return out
<< "Unknown";
1373 struct RGWBucketInfo
{
1374 enum BIShardsHashType
{
1382 ceph::real_time creation_time
;
1383 rgw_placement_rule placement_rule
;
1384 bool has_instance_obj
;
1385 RGWObjVersionTracker objv_tracker
; /* we don't need to serialize this, for runtime tracking */
1386 obj_version ep_objv
; /* entry point object version, for runtime tracking only */
1389 // Represents the number of bucket index object shards:
1390 // - value of 0 indicates there is no sharding (this is by default before this
1391 // feature is implemented).
1392 // - value of UINT32_T::MAX indicates this is a blind bucket.
1393 uint32_t num_shards
;
1395 // Represents the bucket index shard hash type.
1396 uint8_t bucket_index_shard_hash_type
;
1398 // Represents the shard number for blind bucket.
1399 const static uint32_t NUM_SHARDS_BLIND_BUCKET
;
1401 bool requester_pays
;
1404 RGWBucketWebsiteConf website_conf
;
1406 RGWBucketIndexType index_type
= RGWBIType_Normal
;
1408 bool swift_versioning
;
1409 string swift_ver_location
;
1411 map
<string
, uint32_t> mdsearch_config
;
1416 uint8_t reshard_status
;
1417 string new_bucket_instance_id
;
1419 RGWObjectLock obj_lock
;
1421 void encode(bufferlist
& bl
) const {
1422 ENCODE_START(20, 4, bl
);
1424 encode(owner
.id
, bl
);
1426 encode(zonegroup
, bl
);
1427 uint64_t ct
= real_clock::to_time_t(creation_time
);
1429 encode(placement_rule
, bl
);
1430 encode(has_instance_obj
, bl
);
1432 encode(num_shards
, bl
);
1433 encode(bucket_index_shard_hash_type
, bl
);
1434 encode(requester_pays
, bl
);
1435 encode(owner
.tenant
, bl
);
1436 encode(has_website
, bl
);
1438 encode(website_conf
, bl
);
1440 encode((uint32_t)index_type
, bl
);
1441 encode(swift_versioning
, bl
);
1442 if (swift_versioning
) {
1443 encode(swift_ver_location
, bl
);
1445 encode(creation_time
, bl
);
1446 encode(mdsearch_config
, bl
);
1447 encode(reshard_status
, bl
);
1448 encode(new_bucket_instance_id
, bl
);
1449 if (obj_lock_enabled()) {
1450 encode(obj_lock
, bl
);
1454 void decode(bufferlist::const_iterator
& bl
) {
1455 DECODE_START_LEGACY_COMPAT_LEN_32(20, 4, 4, bl
);
1457 if (struct_v
>= 2) {
1465 decode(zonegroup
, bl
);
1466 if (struct_v
>= 6) {
1470 creation_time
= ceph::real_clock::from_time_t((time_t)ct
);
1473 decode(placement_rule
, bl
);
1475 decode(has_instance_obj
, bl
);
1479 decode(num_shards
, bl
);
1481 decode(bucket_index_shard_hash_type
, bl
);
1483 decode(requester_pays
, bl
);
1485 decode(owner
.tenant
, bl
);
1486 if (struct_v
>= 14) {
1487 decode(has_website
, bl
);
1489 decode(website_conf
, bl
);
1491 website_conf
= RGWBucketWebsiteConf();
1494 if (struct_v
>= 15) {
1497 index_type
= (RGWBucketIndexType
)it
;
1499 index_type
= RGWBIType_Normal
;
1501 swift_versioning
= false;
1502 swift_ver_location
.clear();
1503 if (struct_v
>= 16) {
1504 decode(swift_versioning
, bl
);
1505 if (swift_versioning
) {
1506 decode(swift_ver_location
, bl
);
1509 if (struct_v
>= 17) {
1510 decode(creation_time
, bl
);
1512 if (struct_v
>= 18) {
1513 decode(mdsearch_config
, bl
);
1515 if (struct_v
>= 19) {
1516 decode(reshard_status
, bl
);
1517 decode(new_bucket_instance_id
, bl
);
1519 if (struct_v
>= 20 && obj_lock_enabled()) {
1520 decode(obj_lock
, bl
);
1524 void dump(Formatter
*f
) const;
1525 static void generate_test_instances(list
<RGWBucketInfo
*>& o
);
1527 void decode_json(JSONObj
*obj
);
1529 bool versioned() const { return (flags
& BUCKET_VERSIONED
) != 0; }
1530 int versioning_status() const { return flags
& (BUCKET_VERSIONED
| BUCKET_VERSIONS_SUSPENDED
| BUCKET_MFA_ENABLED
); }
1531 bool versioning_enabled() const { return (versioning_status() & (BUCKET_VERSIONED
| BUCKET_VERSIONS_SUSPENDED
)) == BUCKET_VERSIONED
; }
1532 bool mfa_enabled() const { return (versioning_status() & BUCKET_MFA_ENABLED
) != 0; }
1533 bool datasync_flag_enabled() const { return (flags
& BUCKET_DATASYNC_DISABLED
) == 0; }
1534 bool obj_lock_enabled() const { return (flags
& BUCKET_OBJ_LOCK_ENABLED
) != 0; }
1536 bool has_swift_versioning() const {
1537 /* A bucket may be versioned through one mechanism only. */
1538 return swift_versioning
&& !versioned();
1541 RGWBucketInfo() : flags(0), has_instance_obj(false), num_shards(0), bucket_index_shard_hash_type(MOD
), requester_pays(false),
1542 has_website(false), swift_versioning(false), reshard_status(0) {}
1544 WRITE_CLASS_ENCODER(RGWBucketInfo
)
1546 struct RGWBucketEntryPoint
1550 ceph::real_time creation_time
;
1553 bool has_bucket_info
;
1554 RGWBucketInfo old_bucket_info
;
1556 RGWBucketEntryPoint() : linked(false), has_bucket_info(false) {}
1558 void encode(bufferlist
& bl
) const {
1559 ENCODE_START(10, 8, bl
);
1561 encode(owner
.id
, bl
);
1563 uint64_t ctime
= (uint64_t)real_clock::to_time_t(creation_time
);
1566 encode(creation_time
, bl
);
1569 void decode(bufferlist::const_iterator
& bl
) {
1570 auto orig_iter
= bl
;
1571 DECODE_START_LEGACY_COMPAT_LEN_32(10, 4, 4, bl
);
1573 /* ouch, old entry, contains the bucket info itself */
1574 old_bucket_info
.decode(orig_iter
);
1575 has_bucket_info
= true;
1578 has_bucket_info
= false;
1580 decode(owner
.id
, bl
);
1584 if (struct_v
< 10) {
1585 creation_time
= real_clock::from_time_t((time_t)ctime
);
1587 if (struct_v
>= 9) {
1590 if (struct_v
>= 10) {
1591 decode(creation_time
, bl
);
1596 void dump(Formatter
*f
) const;
1597 void decode_json(JSONObj
*obj
);
1599 WRITE_CLASS_ENCODER(RGWBucketEntryPoint
)
1601 struct RGWStorageStats
1603 RGWObjCategory category
;
1605 uint64_t size_rounded
;
1606 uint64_t size_utilized
{0}; //< size after compression, encryption
1607 uint64_t num_objects
;
1610 : category(RGWObjCategory::None
),
1615 void dump(Formatter
*f
) const;
1620 /* Namespaced forward declarations. */
1624 class AWSBrowserUploadAbstractor
;
1637 map
<string
, string
> x_meta_map
;
1643 string request_uri_aws4
;
1644 string effective_uri
;
1645 string request_params
;
1647 string storage_class
;
1649 req_info(CephContext
*cct
, const RGWEnv
*env
);
1650 void rebuild_from(req_info
& src
);
1651 void init_meta_info(bool *found_bad_meta
);
1654 typedef cls_rgw_obj_key rgw_obj_index_key
;
1656 struct rgw_obj_key
{
1662 // cppcheck-suppress noExplicitConstructor
1663 rgw_obj_key(const string
& n
) : name(n
) {}
1664 rgw_obj_key(const string
& n
, const string
& i
) : name(n
), instance(i
) {}
1665 rgw_obj_key(const string
& n
, const string
& i
, const string
& _ns
) : name(n
), instance(i
), ns(_ns
) {}
1667 rgw_obj_key(const rgw_obj_index_key
& k
) {
1668 parse_index_key(k
.name
, &name
, &ns
);
1669 instance
= k
.instance
;
1672 static void parse_index_key(const string
& key
, string
*name
, string
*ns
) {
1673 if (key
[0] != '_') {
1678 if (key
[1] == '_') {
1679 *name
= key
.substr(1);
1683 ssize_t pos
= key
.find('_', 1);
1685 /* shouldn't happen, just use key */
1691 *name
= key
.substr(pos
+ 1);
1692 *ns
= key
.substr(1, pos
-1);
1695 void set(const string
& n
) {
1701 void set(const string
& n
, const string
& i
) {
1707 void set(const string
& n
, const string
& i
, const string
& _ns
) {
1713 bool set(const rgw_obj_index_key
& index_key
) {
1714 if (!parse_raw_oid(index_key
.name
, this)) {
1717 instance
= index_key
.instance
;
1721 void set_instance(const string
& i
) {
1725 const string
& get_instance() const {
1729 string
get_index_key_name() const {
1731 if (name
.size() < 1 || name
[0] != '_') {
1734 return string("_") + name
;
1737 char buf
[ns
.size() + 16];
1738 snprintf(buf
, sizeof(buf
), "_%s_", ns
.c_str());
1739 return string(buf
) + name
;
1742 void get_index_key(rgw_obj_index_key
*key
) const {
1743 key
->name
= get_index_key_name();
1744 key
->instance
= instance
;
1747 string
get_loc() const {
1749 * For backward compatibility. Older versions used to have object locator on all objects,
1750 * however, the name was the effective object locator. This had the same effect as not
1751 * having object locator at all for most objects but the ones that started with underscore as
1752 * these were escaped.
1754 if (name
[0] == '_' && ns
.empty()) {
1761 bool empty() const {
1762 return name
.empty();
1765 bool have_null_instance() const {
1766 return instance
== "null";
1769 bool have_instance() const {
1770 return !instance
.empty();
1773 bool need_to_encode_instance() const {
1774 return have_instance() && !have_null_instance();
1777 string
get_oid() const {
1778 if (ns
.empty() && !need_to_encode_instance()) {
1779 if (name
.size() < 1 || name
[0] != '_') {
1782 return string("_") + name
;
1787 if (need_to_encode_instance()) {
1788 oid
.append(string(":") + instance
);
1795 bool operator==(const rgw_obj_key
& k
) const {
1796 return (name
.compare(k
.name
) == 0) &&
1797 (instance
.compare(k
.instance
) == 0);
1800 bool operator<(const rgw_obj_key
& k
) const {
1801 int r
= name
.compare(k
.name
);
1803 r
= instance
.compare(k
.instance
);
1808 bool operator<=(const rgw_obj_key
& k
) const {
1809 return !(k
< *this);
1812 static void parse_ns_field(string
& ns
, string
& instance
) {
1813 int pos
= ns
.find(':');
1815 instance
= ns
.substr(pos
+ 1);
1816 ns
= ns
.substr(0, pos
);
1822 // takes an oid and parses out the namespace (ns), name, and
1824 static bool parse_raw_oid(const string
& oid
, rgw_obj_key
*key
) {
1825 key
->instance
.clear();
1827 if (oid
[0] != '_') {
1832 if (oid
.size() >= 2 && oid
[1] == '_') {
1833 key
->name
= oid
.substr(1);
1837 if (oid
.size() < 3) // for namespace, min size would be 3: _x_
1840 size_t pos
= oid
.find('_', 2); // oid must match ^_[^_].+$
1841 if (pos
== string::npos
)
1844 key
->ns
= oid
.substr(1, pos
- 1);
1845 parse_ns_field(key
->ns
, key
->instance
);
1847 key
->name
= oid
.substr(pos
+ 1);
1852 * Translate a namespace-mangled object name to the user-facing name
1853 * existing in the given namespace.
1855 * If the object is part of the given namespace, it returns true
1856 * and cuts down the name to the unmangled version. If it is not
1857 * part of the given namespace, it returns false.
1859 static bool oid_to_key_in_ns(const string
& oid
, rgw_obj_key
*key
, const string
& ns
) {
1860 bool ret
= parse_raw_oid(oid
, key
);
1865 return (ns
== key
->ns
);
1869 * Given a mangled object name and an empty namespace string, this
1870 * function extracts the namespace into the string and sets the object
1871 * name to be the unmangled version.
1873 * It returns true after successfully doing so, or
1874 * false if it fails.
1876 static bool strip_namespace_from_name(string
& name
, string
& ns
, string
& instance
) {
1879 if (name
[0] != '_') {
1883 size_t pos
= name
.find('_', 1);
1884 if (pos
== string::npos
) {
1888 if (name
[1] == '_') {
1889 name
= name
.substr(1);
1893 size_t period_pos
= name
.find('.');
1894 if (period_pos
< pos
) {
1898 ns
= name
.substr(1, pos
-1);
1899 name
= name
.substr(pos
+1, string::npos
);
1901 parse_ns_field(ns
, instance
);
1905 void encode(bufferlist
& bl
) const {
1906 ENCODE_START(2, 1, bl
);
1908 encode(instance
, bl
);
1912 void decode(bufferlist::const_iterator
& bl
) {
1913 DECODE_START(2, bl
);
1915 decode(instance
, bl
);
1916 if (struct_v
>= 2) {
1921 void dump(Formatter
*f
) const;
1922 void decode_json(JSONObj
*obj
);
1924 string
to_str() const {
1925 if (instance
.empty()) {
1928 char buf
[name
.size() + instance
.size() + 16];
1929 snprintf(buf
, sizeof(buf
), "%s[%s]", name
.c_str(), instance
.c_str());
1933 WRITE_CLASS_ENCODER(rgw_obj_key
)
1935 inline ostream
& operator<<(ostream
& out
, const rgw_obj_key
&o
) {
1936 return out
<< o
.to_str();
1939 inline ostream
& operator<<(ostream
& out
, const rgw_obj_index_key
&o
) {
1940 if (o
.instance
.empty()) {
1941 return out
<< o
.name
;
1943 return out
<< o
.name
<< "[" << o
.instance
<< "]";
1947 struct req_init_state
{
1948 /* Keeps [[tenant]:]bucket until we parse the token. */
1953 #include "rgw_auth.h"
1956 class RGWSysObjectCtx
;
1958 /** Store all the state necessary to complete and respond to an HTTP request*/
1959 struct req_state
: DoutPrefixProvider
{
1961 rgw::io::BasicClient
*cio
{nullptr};
1962 http_op op
{OP_UNKNOWN
};
1963 RGWOpType op_type
{};
1964 bool content_started
{false};
1966 ceph::Formatter
*formatter
{nullptr};
1968 string relative_uri
;
1969 const char *length
{nullptr};
1970 int64_t content_length
{0};
1971 map
<string
, string
> generic_attrs
;
1973 bool expect_cont
{false};
1974 uint64_t obj_size
{0};
1975 bool enable_ops_log
;
1976 bool enable_usage_log
;
1977 uint8_t defer_to_bucket_acls
;
1978 uint32_t perm_mask
{0};
1980 /* Set once when url_bucket is parsed and not violated thereafter. */
1981 string account_name
;
1983 string bucket_tenant
;
1988 string src_tenant_name
;
1989 string src_bucket_name
;
1990 rgw_obj_key src_object
;
1991 ACLOwner bucket_owner
;
1994 string zonegroup_name
;
1995 string zonegroup_endpoint
;
1996 string bucket_instance_id
;
1997 int bucket_instance_shard_id
{-1};
1998 string redirect_zone_endpoint
;
2002 RGWBucketInfo bucket_info
;
2003 real_time bucket_mtime
;
2004 std::map
<std::string
, ceph::bufferlist
> bucket_attrs
;
2005 bool bucket_exists
{false};
2006 rgw_placement_rule dest_placement
;
2008 bool has_bad_meta
{false};
2013 /* TODO(rzarzynski): switch out to the static_ptr for both members. */
2015 /* Object having the knowledge about an authenticated identity and allowing
2016 * to apply it during the authorization phase (verify_permission() methods
2017 * of a given RGWOp). Thus, it bounds authentication and authorization steps
2018 * through a well-defined interface. For more details, see rgw_auth.h. */
2019 std::unique_ptr
<rgw::auth::Identity
> identity
;
2021 std::shared_ptr
<rgw::auth::Completer
> completer
;
2023 /* A container for credentials of the S3's browser upload. It's necessary
2024 * because: 1) the ::authenticate() method of auth engines and strategies
2025 * take req_state only; 2) auth strategies live much longer than RGWOps -
2026 * there is no way to pass additional data dependencies through ctors. */
2029 friend class RGWPostObj_ObjStore_S3
;
2031 friend class rgw::auth::s3::AWSBrowserUploadAbstractor
;
2033 std::string access_key
;
2034 std::string signature
;
2035 std::string x_amz_algorithm
;
2036 std::string x_amz_credential
;
2037 std::string x_amz_date
;
2038 std::string x_amz_security_token
;
2039 ceph::bufferlist encoded_policy
;
2043 std::unique_ptr
<RGWAccessControlPolicy
> user_acl
;
2044 std::unique_ptr
<RGWAccessControlPolicy
> bucket_acl
;
2045 std::unique_ptr
<RGWAccessControlPolicy
> object_acl
;
2047 rgw::IAM::Environment env
;
2048 boost::optional
<rgw::IAM::Policy
> iam_policy
;
2049 vector
<rgw::IAM::Policy
> iam_user_policies
;
2051 /* Is the request made by an user marked as a system one?
2052 * Being system user means we also have the admin status. */
2053 bool system_request
{false};
2056 bool has_acl_header
{false};
2057 bool local_source
{false}; /* source is local */
2061 /* Content-Disposition override for TempURL of Swift API. */
2070 req_init_state init_state
;
2072 using Clock
= ceph::coarse_real_clock
;
2073 Clock::time_point time
;
2075 Clock::duration
time_elapsed() const { return Clock::now() - time
; }
2077 RGWObjectCtx
*obj_ctx
{nullptr};
2078 RGWSysObjectCtx
*sysobj_ctx
{nullptr};
2084 bool mfa_verified
{false};
2086 /// optional coroutine context
2087 optional_yield yield
{null_yield
};
2089 req_state(CephContext
* _cct
, RGWEnv
* e
, RGWUserInfo
* u
, uint64_t id
);
2092 bool is_err() const { return err
.is_err(); }
2094 // implements DoutPrefixProvider
2095 std::ostream
& gen_prefix(std::ostream
& out
) const override
;
2096 CephContext
* get_cct() const override
{ return cct
; }
2097 unsigned get_subsys() const override
{ return ceph_subsys_rgw
; }
2100 void set_req_state_err(struct req_state
*, int);
2101 void set_req_state_err(struct req_state
*, int, const string
&);
2102 void set_req_state_err(struct rgw_err
&, int, const int);
2103 void dump(struct req_state
*);
2105 /** Store basic data on bucket */
2106 struct RGWBucketEnt
{
2109 size_t size_rounded
;
2110 ceph::real_time creation_time
;
2113 /* The placement_rule is necessary to calculate per-storage-policy statics
2114 * of the Swift API. Although the info available in RGWBucketInfo, we need
2115 * to duplicate it here to not affect the performance of buckets listing. */
2116 rgw_placement_rule placement_rule
;
2123 RGWBucketEnt(const RGWBucketEnt
&) = default;
2124 RGWBucketEnt(RGWBucketEnt
&&) = default;
2125 explicit RGWBucketEnt(const rgw_user
& u
, cls_user_bucket_entry
&& e
)
2126 : bucket(u
, std::move(e
.bucket
)),
2128 size_rounded(e
.size_rounded
),
2129 creation_time(e
.creation_time
),
2133 RGWBucketEnt
& operator=(const RGWBucketEnt
&) = default;
2135 void convert(cls_user_bucket_entry
*b
) const {
2136 bucket
.convert(&b
->bucket
);
2138 b
->size_rounded
= size_rounded
;
2139 b
->creation_time
= creation_time
;
2143 void encode(bufferlist
& bl
) const {
2144 ENCODE_START(7, 5, bl
);
2146 __u32 mt
= ceph::real_clock::to_time_t(creation_time
);
2147 string empty_str
; // originally had the bucket name here, but we encode bucket later
2148 encode(empty_str
, bl
);
2155 encode(creation_time
, bl
);
2156 encode(placement_rule
, bl
);
2159 void decode(bufferlist::const_iterator
& bl
) {
2160 DECODE_START_LEGACY_COMPAT_LEN(7, 5, 5, bl
);
2163 string empty_str
; // backward compatibility
2164 decode(empty_str
, bl
);
2169 creation_time
= ceph::real_clock::from_time_t(mt
);
2179 decode(creation_time
, bl
);
2181 decode(placement_rule
, bl
);
2184 void dump(Formatter
*f
) const;
2185 static void generate_test_instances(list
<RGWBucketEnt
*>& o
);
2187 WRITE_CLASS_ENCODER(RGWBucketEnt
)
2193 bool in_extra_data
{false}; /* in-memory only member, does not serialize */
2195 // Represents the hash index source for this object once it is set (non-empty)
2196 std::string index_hash_source
;
2199 rgw_obj(const rgw_bucket
& b
, const std::string
& name
) : bucket(b
), key(name
) {}
2200 rgw_obj(const rgw_bucket
& b
, const rgw_obj_key
& k
) : bucket(b
), key(k
) {}
2201 rgw_obj(const rgw_bucket
& b
, const rgw_obj_index_key
& k
) : bucket(b
), key(k
) {}
2203 void init(const rgw_bucket
& b
, const std::string
& name
) {
2207 void init(const rgw_bucket
& b
, const std::string
& name
, const string
& i
, const string
& n
) {
2209 key
.set(name
, i
, n
);
2211 void init_ns(const rgw_bucket
& b
, const std::string
& name
, const string
& n
) {
2214 key
.instance
.clear();
2218 bool empty() const {
2222 void set_key(const rgw_obj_key
& k
) {
2226 string
get_oid() const {
2227 return key
.get_oid();
2230 const string
& get_hash_object() const {
2231 return index_hash_source
.empty() ? key
.name
: index_hash_source
;
2234 void set_in_extra_data(bool val
) {
2235 in_extra_data
= val
;
2238 bool is_in_extra_data() const {
2239 return in_extra_data
;
2242 void encode(bufferlist
& bl
) const {
2243 ENCODE_START(6, 6, bl
);
2246 encode(key
.name
, bl
);
2247 encode(key
.instance
, bl
);
2248 // encode(placement_id, bl);
2251 void decode(bufferlist::const_iterator
& bl
) {
2252 DECODE_START_LEGACY_COMPAT_LEN(6, 3, 3, bl
);
2255 decode(bucket
.name
, bl
); /* bucket.name */
2256 decode(s
, bl
); /* loc */
2258 decode(key
.name
, bl
);
2262 decode(key
.instance
, bl
);
2263 if (key
.ns
.empty() && key
.instance
.empty()) {
2264 if (key
.name
[0] == '_') {
2265 key
.name
= key
.name
.substr(1);
2268 if (struct_v
>= 5) {
2269 decode(key
.name
, bl
);
2271 ssize_t pos
= key
.name
.find('_', 1);
2273 throw buffer::error();
2275 key
.name
= key
.name
.substr(pos
+ 1);
2281 decode(key
.name
, bl
);
2282 decode(key
.instance
, bl
);
2283 // decode(placement_id, bl);
2287 void dump(Formatter
*f
) const;
2288 static void generate_test_instances(list
<rgw_obj
*>& o
);
2290 bool operator==(const rgw_obj
& o
) const {
2291 return (key
== o
.key
) &&
2292 (bucket
== o
.bucket
);
2294 bool operator<(const rgw_obj
& o
) const {
2295 int r
= key
.name
.compare(o
.key
.name
);
2297 r
= bucket
.bucket_id
.compare(o
.bucket
.bucket_id
); /* not comparing bucket.name, if bucket_id is equal so will be bucket.name */
2299 r
= key
.ns
.compare(o
.key
.ns
);
2301 r
= key
.instance
.compare(o
.key
.instance
);
2309 const rgw_pool
& get_explicit_data_pool() {
2310 if (!in_extra_data
|| bucket
.explicit_placement
.data_extra_pool
.empty()) {
2311 return bucket
.explicit_placement
.data_pool
;
2313 return bucket
.explicit_placement
.data_extra_pool
;
2316 WRITE_CLASS_ENCODER(rgw_obj
)
2318 struct rgw_cache_entry_info
{
2319 string cache_locator
;
2322 rgw_cache_entry_info() : gen(0) {}
2325 inline ostream
& operator<<(ostream
& out
, const rgw_obj
&o
) {
2326 return out
<< o
.bucket
.name
<< ":" << o
.get_oid();
2329 static inline void buf_to_hex(const unsigned char* const buf
,
2334 for (size_t i
= 0; i
< len
; i
++) {
2335 ::sprintf(&str
[i
*2], "%02x", static_cast<int>(buf
[i
]));
2339 template<size_t N
> static inline std::array
<char, N
* 2 + 1>
2340 buf_to_hex(const std::array
<unsigned char, N
>& buf
)
2342 static_assert(N
> 0, "The input array must be at least one element long");
2344 std::array
<char, N
* 2 + 1> hex_dest
;
2345 buf_to_hex(buf
.data(), N
, hex_dest
.data());
2349 static inline int hexdigit(char c
)
2351 if (c
>= '0' && c
<= '9')
2354 if (c
>= 'A' && c
<= 'F')
2355 return c
- 'A' + 0xa;
2359 static inline int hex_to_buf(const char *hex
, char *buf
, int len
)
2362 const char *p
= hex
;
2367 int d
= hexdigit(*p
);
2384 static inline int rgw_str_to_bool(const char *s
, int def_val
)
2389 return (strcasecmp(s
, "true") == 0 ||
2390 strcasecmp(s
, "on") == 0 ||
2391 strcasecmp(s
, "yes") == 0 ||
2392 strcasecmp(s
, "1") == 0);
2395 static inline void append_rand_alpha(CephContext
*cct
, const string
& src
, string
& dest
, int len
)
2399 gen_rand_alphanumeric(cct
, buf
, len
);
2404 static inline const char *rgw_obj_category_name(RGWObjCategory category
)
2407 case RGWObjCategory::None
:
2409 case RGWObjCategory::Main
:
2411 case RGWObjCategory::Shadow
:
2412 return "rgw.shadow";
2413 case RGWObjCategory::MultiMeta
:
2414 return "rgw.multimeta";
2420 static inline uint64_t rgw_rounded_kb(uint64_t bytes
)
2422 return (bytes
+ 1023) / 1024;
2425 static inline uint64_t rgw_rounded_objsize(uint64_t bytes
)
2427 return ((bytes
+ 4095) & ~4095);
2430 static inline uint64_t rgw_rounded_objsize_kb(uint64_t bytes
)
2432 return ((bytes
+ 4095) & ~4095) / 1024;
2435 /* implement combining step, S3 header canonicalization; k is a
2436 * valid header and in lc form */
2437 static inline void add_amz_meta_header(
2438 std::map
<std::string
, std::string
>& x_meta_map
,
2439 const std::string
& k
,
2440 const std::string
& v
)
2442 auto it
= x_meta_map
.find(k
);
2443 if (it
!= x_meta_map
.end()) {
2444 std::string old
= it
->second
;
2445 boost::algorithm::trim_right(old
);
2448 x_meta_map
[k
] = old
;
2452 } /* add_amz_meta_header */
2454 extern string
rgw_string_unquote(const string
& s
);
2455 extern void parse_csv_string(const string
& ival
, vector
<string
>& ovals
);
2456 extern int parse_key_value(string
& in_str
, string
& key
, string
& val
);
2457 extern int parse_key_value(string
& in_str
, const char *delim
, string
& key
, string
& val
);
2459 extern boost::optional
<std::pair
<boost::string_view
, boost::string_view
>>
2460 parse_key_value(const boost::string_view
& in_str
,
2461 const boost::string_view
& delim
);
2462 extern boost::optional
<std::pair
<boost::string_view
, boost::string_view
>>
2463 parse_key_value(const boost::string_view
& in_str
);
2467 extern int parse_time(const char *time_str
, real_time
*time
);
2468 extern bool parse_rfc2616(const char *s
, struct tm
*t
);
2469 extern bool parse_iso8601(const char *s
, struct tm
*t
, uint32_t *pns
= NULL
, bool extended_format
= true);
2470 extern string
rgw_trim_whitespace(const string
& src
);
2471 extern boost::string_view
rgw_trim_whitespace(const boost::string_view
& src
);
2472 extern string
rgw_trim_quotes(const string
& val
);
2474 extern void rgw_to_iso8601(const real_time
& t
, char *dest
, int buf_size
);
2475 extern void rgw_to_iso8601(const real_time
& t
, string
*dest
);
2476 extern std::string
rgw_to_asctime(const utime_t
& t
);
2478 /** Check if the req_state's user has the necessary permissions
2479 * to do the requested action */
2480 rgw::IAM::Effect
eval_user_policies(const vector
<rgw::IAM::Policy
>& user_policies
,
2481 const rgw::IAM::Environment
& env
,
2482 boost::optional
<const rgw::auth::Identity
&> id
,
2484 const rgw::ARN
& arn
);
2485 bool verify_user_permission(const DoutPrefixProvider
* dpp
,
2486 struct req_state
* const s
,
2487 RGWAccessControlPolicy
* const user_acl
,
2488 const vector
<rgw::IAM::Policy
>& user_policies
,
2489 const rgw::ARN
& res
,
2491 bool verify_user_permission_no_policy(const DoutPrefixProvider
* dpp
,
2492 struct req_state
* const s
,
2493 RGWAccessControlPolicy
* const user_acl
,
2495 bool verify_user_permission(const DoutPrefixProvider
* dpp
,
2496 struct req_state
* const s
,
2497 const rgw::ARN
& res
,
2499 bool verify_user_permission_no_policy(const DoutPrefixProvider
* dpp
,
2500 struct req_state
* const s
,
2502 bool verify_bucket_permission(
2503 const DoutPrefixProvider
* dpp
,
2504 struct req_state
* const s
,
2505 const rgw_bucket
& bucket
,
2506 RGWAccessControlPolicy
* const user_acl
,
2507 RGWAccessControlPolicy
* const bucket_acl
,
2508 const boost::optional
<rgw::IAM::Policy
>& bucket_policy
,
2509 const vector
<rgw::IAM::Policy
>& user_policies
,
2511 bool verify_bucket_permission(const DoutPrefixProvider
* dpp
, struct req_state
* const s
, const uint64_t op
);
2512 bool verify_bucket_permission_no_policy(
2513 const DoutPrefixProvider
* dpp
,
2514 struct req_state
* const s
,
2515 RGWAccessControlPolicy
* const user_acl
,
2516 RGWAccessControlPolicy
* const bucket_acl
,
2518 bool verify_bucket_permission_no_policy(const DoutPrefixProvider
* dpp
,
2519 struct req_state
* const s
,
2521 int verify_bucket_owner_or_policy(struct req_state
* const s
,
2523 extern bool verify_object_permission(
2524 const DoutPrefixProvider
* dpp
,
2525 struct req_state
* const s
,
2527 RGWAccessControlPolicy
* const user_acl
,
2528 RGWAccessControlPolicy
* const bucket_acl
,
2529 RGWAccessControlPolicy
* const object_acl
,
2530 const boost::optional
<rgw::IAM::Policy
>& bucket_policy
,
2531 const vector
<rgw::IAM::Policy
>& user_policies
,
2533 extern bool verify_object_permission(const DoutPrefixProvider
* dpp
, struct req_state
*s
, uint64_t op
);
2534 extern bool verify_object_permission_no_policy(
2535 const DoutPrefixProvider
* dpp
,
2536 struct req_state
* const s
,
2537 RGWAccessControlPolicy
* const user_acl
,
2538 RGWAccessControlPolicy
* const bucket_acl
,
2539 RGWAccessControlPolicy
* const object_acl
,
2541 extern bool verify_object_permission_no_policy(const DoutPrefixProvider
* dpp
, struct req_state
*s
,
2543 /** Convert an input URL into a sane object name
2544 * by converting %-escaped strings into characters, etc*/
2545 extern void rgw_uri_escape_char(char c
, string
& dst
);
2546 extern std::string
url_decode(const boost::string_view
& src_str
,
2547 bool in_query
= false);
2548 extern void url_encode(const std::string
& src
, string
& dst
,
2549 bool encode_slash
= true);
2550 extern std::string
url_encode(const std::string
& src
, bool encode_slash
= true);
2551 /* destination should be CEPH_CRYPTO_HMACSHA1_DIGESTSIZE bytes long */
2552 extern void calc_hmac_sha1(const char *key
, int key_len
,
2553 const char *msg
, int msg_len
, char *dest
);
2555 static inline sha1_digest_t
2556 calc_hmac_sha1(const boost::string_view
& key
, const boost::string_view
& msg
) {
2558 calc_hmac_sha1(key
.data(), key
.size(), msg
.data(), msg
.size(),
2559 reinterpret_cast<char*>(dest
.v
));
2563 /* destination should be CEPH_CRYPTO_HMACSHA256_DIGESTSIZE bytes long */
2564 extern void calc_hmac_sha256(const char *key
, int key_len
,
2565 const char *msg
, int msg_len
,
2568 static inline sha256_digest_t
2569 calc_hmac_sha256(const char *key
, const int key_len
,
2570 const char *msg
, const int msg_len
) {
2571 sha256_digest_t dest
;
2572 calc_hmac_sha256(key
, key_len
, msg
, msg_len
,
2573 reinterpret_cast<char*>(dest
.v
));
2577 static inline sha256_digest_t
2578 calc_hmac_sha256(const boost::string_view
& key
, const boost::string_view
& msg
) {
2579 sha256_digest_t dest
;
2580 calc_hmac_sha256(key
.data(), key
.size(),
2581 msg
.data(), msg
.size(),
2582 reinterpret_cast<char*>(dest
.v
));
2586 static inline sha256_digest_t
2587 calc_hmac_sha256(const sha256_digest_t
&key
,
2588 const boost::string_view
& msg
) {
2589 sha256_digest_t dest
;
2590 calc_hmac_sha256(reinterpret_cast<const char*>(key
.v
), sha256_digest_t::SIZE
,
2591 msg
.data(), msg
.size(),
2592 reinterpret_cast<char*>(dest
.v
));
2596 static inline sha256_digest_t
2597 calc_hmac_sha256(const std::vector
<unsigned char>& key
,
2598 const boost::string_view
& msg
) {
2599 sha256_digest_t dest
;
2600 calc_hmac_sha256(reinterpret_cast<const char*>(key
.data()), key
.size(),
2601 msg
.data(), msg
.size(),
2602 reinterpret_cast<char*>(dest
.v
));
2606 template<size_t KeyLenN
>
2607 static inline sha256_digest_t
2608 calc_hmac_sha256(const std::array
<unsigned char, KeyLenN
>& key
,
2609 const boost::string_view
& msg
) {
2610 sha256_digest_t dest
;
2611 calc_hmac_sha256(reinterpret_cast<const char*>(key
.data()), key
.size(),
2612 msg
.data(), msg
.size(),
2613 reinterpret_cast<char*>(dest
.v
));
2617 extern sha256_digest_t
calc_hash_sha256(const boost::string_view
& msg
);
2619 extern ceph::crypto::SHA256
* calc_hash_sha256_open_stream();
2620 extern void calc_hash_sha256_update_stream(ceph::crypto::SHA256
* hash
,
2623 extern std::string
calc_hash_sha256_close_stream(ceph::crypto::SHA256
** phash
);
2624 extern std::string
calc_hash_sha256_restart_stream(ceph::crypto::SHA256
** phash
);
2626 extern int rgw_parse_op_type_list(const string
& str
, uint32_t *perm
);
2628 static constexpr uint32_t MATCH_POLICY_ACTION
= 0x01;
2629 static constexpr uint32_t MATCH_POLICY_RESOURCE
= 0x02;
2630 static constexpr uint32_t MATCH_POLICY_ARN
= 0x04;
2631 static constexpr uint32_t MATCH_POLICY_STRING
= 0x08;
2633 extern bool match_policy(boost::string_view pattern
, boost::string_view input
,
2636 extern string
camelcase_dash_http_attr(const string
& orig
);
2637 extern string
lowercase_dash_http_attr(const string
& orig
);
2639 void rgw_setup_saved_curl_handles();
2640 void rgw_release_all_curl_handles();
2642 static inline void rgw_escape_str(const string
& s
, char esc_char
,
2643 char special_char
, string
*dest
)
2645 const char *src
= s
.c_str();
2646 char dest_buf
[s
.size() * 2 + 1];
2647 char *destp
= dest_buf
;
2649 for (size_t i
= 0; i
< s
.size(); i
++) {
2651 if (c
== esc_char
|| c
== special_char
) {
2652 *destp
++ = esc_char
;
2660 static inline ssize_t
rgw_unescape_str(const string
& s
, ssize_t ofs
,
2661 char esc_char
, char special_char
,
2664 const char *src
= s
.c_str();
2665 char dest_buf
[s
.size() + 1];
2666 char *destp
= dest_buf
;
2671 for (size_t i
= ofs
; i
< s
.size(); i
++) {
2673 if (!esc
&& c
== esc_char
) {
2677 if (!esc
&& c
== special_char
) {
2680 return (ssize_t
)i
+ 1;
2687 return string::npos
;
2690 static inline string
rgw_bl_str(ceph::buffer::list
& raw
)
2692 size_t len
= raw
.length();
2693 string
s(raw
.c_str(), len
);
2694 while (len
&& !s
[len
- 1]) {
2701 template <typename T
>
2702 int decode_bl(bufferlist
& bl
, T
& t
)
2704 auto iter
= bl
.cbegin();
2707 } catch (buffer::error
& err
) {