]>
Commit | Line | Data |
---|---|---|
7c673cae FG |
1 | // -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*- |
2 | // vim: ts=8 sw=2 smarttab | |
3 | /* | |
4 | * Ceph - scalable distributed file system | |
5 | * | |
6 | * Copyright (C) 2004-2009 Sage Weil <sage@newdream.net> | |
7 | * Copyright (C) 2015 Yehuda Sadeh <yehuda@redhat.com> | |
8 | * | |
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. | |
13 | * | |
14 | */ | |
15 | ||
16 | #ifndef CEPH_RGW_COMMON_H | |
17 | #define CEPH_RGW_COMMON_H | |
18 | ||
19 | #include "common/ceph_crypto.h" | |
20 | #include "common/perf_counters.h" | |
21 | #include "acconfig.h" | |
22 | #include "rgw_acl.h" | |
23 | #include "rgw_cors.h" | |
24 | #include "rgw_quota.h" | |
25 | #include "rgw_string.h" | |
26 | #include "rgw_website.h" | |
27 | #include "cls/version/cls_version_types.h" | |
28 | #include "cls/user/cls_user_types.h" | |
29 | #include "cls/rgw/cls_rgw_types.h" | |
30 | #include "include/rados/librados.hpp" | |
31 | ||
32 | using namespace std; | |
33 | ||
34 | namespace ceph { | |
35 | class Formatter; | |
36 | } | |
37 | ||
38 | using ceph::crypto::MD5; | |
39 | ||
40 | ||
41 | #define RGW_ATTR_PREFIX "user.rgw." | |
42 | ||
43 | #define RGW_HTTP_RGWX_ATTR_PREFIX "RGWX_ATTR_" | |
44 | #define RGW_HTTP_RGWX_ATTR_PREFIX_OUT "Rgwx-Attr-" | |
45 | ||
46 | #define RGW_AMZ_PREFIX "x-amz-" | |
47 | #define RGW_AMZ_META_PREFIX RGW_AMZ_PREFIX "meta-" | |
48 | #define RGW_AMZ_WEBSITE_REDIRECT_LOCATION RGW_AMZ_PREFIX "website-redirect-location" | |
49 | ||
50 | #define RGW_SYS_PARAM_PREFIX "rgwx-" | |
51 | ||
52 | #define RGW_ATTR_ACL RGW_ATTR_PREFIX "acl" | |
53 | #define RGW_ATTR_LC RGW_ATTR_PREFIX "lc" | |
54 | #define RGW_ATTR_CORS RGW_ATTR_PREFIX "cors" | |
55 | #define RGW_ATTR_ETAG RGW_ATTR_PREFIX "etag" | |
56 | #define RGW_ATTR_BUCKETS RGW_ATTR_PREFIX "buckets" | |
57 | #define RGW_ATTR_META_PREFIX RGW_ATTR_PREFIX RGW_AMZ_META_PREFIX | |
58 | #define RGW_ATTR_CONTENT_TYPE RGW_ATTR_PREFIX "content_type" | |
59 | #define RGW_ATTR_CACHE_CONTROL RGW_ATTR_PREFIX "cache_control" | |
60 | #define RGW_ATTR_CONTENT_DISP RGW_ATTR_PREFIX "content_disposition" | |
61 | #define RGW_ATTR_CONTENT_ENC RGW_ATTR_PREFIX "content_encoding" | |
62 | #define RGW_ATTR_CONTENT_LANG RGW_ATTR_PREFIX "content_language" | |
63 | #define RGW_ATTR_EXPIRES RGW_ATTR_PREFIX "expires" | |
64 | #define RGW_ATTR_DELETE_AT RGW_ATTR_PREFIX "delete_at" | |
65 | #define RGW_ATTR_ID_TAG RGW_ATTR_PREFIX "idtag" | |
66 | #define RGW_ATTR_SHADOW_OBJ RGW_ATTR_PREFIX "shadow_name" | |
67 | #define RGW_ATTR_MANIFEST RGW_ATTR_PREFIX "manifest" | |
68 | #define RGW_ATTR_USER_MANIFEST RGW_ATTR_PREFIX "user_manifest" | |
69 | #define RGW_ATTR_AMZ_WEBSITE_REDIRECT_LOCATION RGW_ATTR_PREFIX RGW_AMZ_WEBSITE_REDIRECT_LOCATION | |
70 | #define RGW_ATTR_SLO_MANIFEST RGW_ATTR_PREFIX "slo_manifest" | |
71 | /* Information whether an object is SLO or not must be exposed to | |
72 | * user through custom HTTP header named X-Static-Large-Object. */ | |
73 | #define RGW_ATTR_SLO_UINDICATOR RGW_ATTR_META_PREFIX "static-large-object" | |
74 | #define RGW_ATTR_X_ROBOTS_TAG RGW_ATTR_PREFIX "x-robots-tag" | |
75 | ||
76 | #define RGW_ATTR_PG_VER RGW_ATTR_PREFIX "pg_ver" | |
77 | #define RGW_ATTR_SOURCE_ZONE RGW_ATTR_PREFIX "source_zone" | |
78 | ||
79 | #define RGW_ATTR_TEMPURL_KEY1 RGW_ATTR_META_PREFIX "temp-url-key" | |
80 | #define RGW_ATTR_TEMPURL_KEY2 RGW_ATTR_META_PREFIX "temp-url-key-2" | |
81 | ||
82 | /* Account/container quota of the Swift API. */ | |
83 | #define RGW_ATTR_QUOTA_NOBJS RGW_ATTR_META_PREFIX "quota-count" | |
84 | #define RGW_ATTR_QUOTA_MSIZE RGW_ATTR_META_PREFIX "quota-bytes" | |
85 | ||
86 | /* Static Web Site of Swift API. */ | |
87 | #define RGW_ATTR_WEB_INDEX RGW_ATTR_META_PREFIX "web-index" | |
88 | #define RGW_ATTR_WEB_ERROR RGW_ATTR_META_PREFIX "web-error" | |
89 | #define RGW_ATTR_WEB_LISTINGS RGW_ATTR_META_PREFIX "web-listings" | |
90 | #define RGW_ATTR_WEB_LIST_CSS RGW_ATTR_META_PREFIX "web-listings-css" | |
91 | #define RGW_ATTR_SUBDIR_MARKER RGW_ATTR_META_PREFIX "web-directory-type" | |
92 | ||
93 | #define RGW_ATTR_OLH_PREFIX RGW_ATTR_PREFIX "olh." | |
94 | ||
95 | #define RGW_ATTR_OLH_INFO RGW_ATTR_OLH_PREFIX "info" | |
96 | #define RGW_ATTR_OLH_VER RGW_ATTR_OLH_PREFIX "ver" | |
97 | #define RGW_ATTR_OLH_ID_TAG RGW_ATTR_OLH_PREFIX "idtag" | |
98 | #define RGW_ATTR_OLH_PENDING_PREFIX RGW_ATTR_OLH_PREFIX "pending." | |
99 | ||
100 | #define RGW_ATTR_COMPRESSION RGW_ATTR_PREFIX "compression" | |
101 | ||
102 | /* RGW File Attributes */ | |
103 | #define RGW_ATTR_UNIX_KEY1 RGW_ATTR_PREFIX "unix-key1" | |
104 | #define RGW_ATTR_UNIX1 RGW_ATTR_PREFIX "unix1" | |
105 | ||
106 | #define RGW_ATTR_CRYPT_PREFIX RGW_ATTR_PREFIX "crypt." | |
107 | #define RGW_ATTR_CRYPT_MODE RGW_ATTR_CRYPT_PREFIX "mode" | |
108 | #define RGW_ATTR_CRYPT_KEYMD5 RGW_ATTR_CRYPT_PREFIX "keymd5" | |
109 | #define RGW_ATTR_CRYPT_KEYID RGW_ATTR_CRYPT_PREFIX "keyid" | |
110 | #define RGW_ATTR_CRYPT_KEYSEL RGW_ATTR_CRYPT_PREFIX "keysel" | |
111 | ||
112 | #define RGW_BUCKETS_OBJ_SUFFIX ".buckets" | |
113 | ||
114 | #define RGW_FORMAT_PLAIN 0 | |
115 | #define RGW_FORMAT_XML 1 | |
116 | #define RGW_FORMAT_JSON 2 | |
117 | #define RGW_FORMAT_HTML 3 | |
118 | ||
119 | #define RGW_CAP_READ 0x1 | |
120 | #define RGW_CAP_WRITE 0x2 | |
121 | #define RGW_CAP_ALL (RGW_CAP_READ | RGW_CAP_WRITE) | |
122 | ||
123 | #define RGW_REST_SWIFT 0x1 | |
124 | #define RGW_REST_SWIFT_AUTH 0x2 | |
125 | #define RGW_REST_S3 0x4 | |
126 | #define RGW_REST_WEBSITE 0x8 | |
127 | ||
128 | #define RGW_SUSPENDED_USER_AUID (uint64_t)-2 | |
129 | ||
130 | #define RGW_OP_TYPE_READ 0x01 | |
131 | #define RGW_OP_TYPE_WRITE 0x02 | |
132 | #define RGW_OP_TYPE_DELETE 0x04 | |
133 | ||
134 | #define RGW_OP_TYPE_MODIFY (RGW_OP_TYPE_WRITE | RGW_OP_TYPE_DELETE) | |
135 | #define RGW_OP_TYPE_ALL (RGW_OP_TYPE_READ | RGW_OP_TYPE_WRITE | RGW_OP_TYPE_DELETE) | |
136 | ||
137 | #define RGW_DEFAULT_MAX_BUCKETS 1000 | |
138 | ||
139 | #define RGW_DEFER_TO_BUCKET_ACLS_RECURSE 1 | |
140 | #define RGW_DEFER_TO_BUCKET_ACLS_FULL_CONTROL 2 | |
141 | ||
142 | #define STATUS_CREATED 1900 | |
143 | #define STATUS_ACCEPTED 1901 | |
144 | #define STATUS_NO_CONTENT 1902 | |
145 | #define STATUS_PARTIAL_CONTENT 1903 | |
146 | #define STATUS_REDIRECT 1904 | |
147 | #define STATUS_NO_APPLY 1905 | |
148 | #define STATUS_APPLIED 1906 | |
149 | ||
150 | #define ERR_INVALID_BUCKET_NAME 2000 | |
151 | #define ERR_INVALID_OBJECT_NAME 2001 | |
152 | #define ERR_NO_SUCH_BUCKET 2002 | |
153 | #define ERR_METHOD_NOT_ALLOWED 2003 | |
154 | #define ERR_INVALID_DIGEST 2004 | |
155 | #define ERR_BAD_DIGEST 2005 | |
156 | #define ERR_UNRESOLVABLE_EMAIL 2006 | |
157 | #define ERR_INVALID_PART 2007 | |
158 | #define ERR_INVALID_PART_ORDER 2008 | |
159 | #define ERR_NO_SUCH_UPLOAD 2009 | |
160 | #define ERR_REQUEST_TIMEOUT 2010 | |
161 | #define ERR_LENGTH_REQUIRED 2011 | |
162 | #define ERR_REQUEST_TIME_SKEWED 2012 | |
163 | #define ERR_BUCKET_EXISTS 2013 | |
164 | #define ERR_BAD_URL 2014 | |
165 | #define ERR_PRECONDITION_FAILED 2015 | |
166 | #define ERR_NOT_MODIFIED 2016 | |
167 | #define ERR_INVALID_UTF8 2017 | |
168 | #define ERR_UNPROCESSABLE_ENTITY 2018 | |
169 | #define ERR_TOO_LARGE 2019 | |
170 | #define ERR_TOO_MANY_BUCKETS 2020 | |
171 | #define ERR_INVALID_REQUEST 2021 | |
172 | #define ERR_TOO_SMALL 2022 | |
173 | #define ERR_NOT_FOUND 2023 | |
174 | #define ERR_PERMANENT_REDIRECT 2024 | |
175 | #define ERR_LOCKED 2025 | |
176 | #define ERR_QUOTA_EXCEEDED 2026 | |
177 | #define ERR_SIGNATURE_NO_MATCH 2027 | |
178 | #define ERR_INVALID_ACCESS_KEY 2028 | |
179 | #define ERR_MALFORMED_XML 2029 | |
180 | #define ERR_USER_EXIST 2030 | |
181 | #define ERR_NOT_SLO_MANIFEST 2031 | |
182 | #define ERR_EMAIL_EXIST 2032 | |
183 | #define ERR_KEY_EXIST 2033 | |
184 | #define ERR_INVALID_SECRET_KEY 2034 | |
185 | #define ERR_INVALID_KEY_TYPE 2035 | |
186 | #define ERR_INVALID_CAP 2036 | |
187 | #define ERR_INVALID_TENANT_NAME 2037 | |
188 | #define ERR_WEBSITE_REDIRECT 2038 | |
189 | #define ERR_NO_SUCH_WEBSITE_CONFIGURATION 2039 | |
190 | #define ERR_AMZ_CONTENT_SHA256_MISMATCH 2040 | |
191 | #define ERR_NO_SUCH_LC 2041 | |
192 | #define ERR_USER_SUSPENDED 2100 | |
193 | #define ERR_INTERNAL_ERROR 2200 | |
194 | #define ERR_NOT_IMPLEMENTED 2201 | |
195 | #define ERR_SERVICE_UNAVAILABLE 2202 | |
196 | #define ERR_ROLE_EXISTS 2203 | |
197 | #define ERR_MALFORMED_DOC 2204 | |
198 | #define ERR_NO_ROLE_FOUND 2205 | |
199 | #define ERR_DELETE_CONFLICT 2206 | |
200 | ||
201 | #ifndef UINT32_MAX | |
202 | #define UINT32_MAX (0xffffffffu) | |
203 | #endif | |
204 | ||
205 | typedef void *RGWAccessHandle; | |
206 | ||
207 | ||
208 | /* perf counter */ | |
209 | ||
210 | extern PerfCounters *perfcounter; | |
211 | ||
212 | extern int rgw_perf_start(CephContext *cct); | |
213 | extern void rgw_perf_stop(CephContext *cct); | |
214 | ||
215 | enum { | |
216 | l_rgw_first = 15000, | |
217 | l_rgw_req, | |
218 | l_rgw_failed_req, | |
219 | ||
220 | l_rgw_get, | |
221 | l_rgw_get_b, | |
222 | l_rgw_get_lat, | |
223 | ||
224 | l_rgw_put, | |
225 | l_rgw_put_b, | |
226 | l_rgw_put_lat, | |
227 | ||
228 | l_rgw_qlen, | |
229 | l_rgw_qactive, | |
230 | ||
231 | l_rgw_cache_hit, | |
232 | l_rgw_cache_miss, | |
233 | ||
234 | l_rgw_keystone_token_cache_hit, | |
235 | l_rgw_keystone_token_cache_miss, | |
236 | ||
237 | l_rgw_last, | |
238 | }; | |
239 | ||
240 | ||
241 | /* size should be the required string size + 1 */ | |
242 | extern int gen_rand_base64(CephContext *cct, char *dest, int size); | |
243 | extern int gen_rand_alphanumeric(CephContext *cct, char *dest, int size); | |
244 | extern int gen_rand_alphanumeric_lower(CephContext *cct, char *dest, int size); | |
245 | extern int gen_rand_alphanumeric_upper(CephContext *cct, char *dest, int size); | |
246 | extern int gen_rand_alphanumeric_no_underscore(CephContext *cct, char *dest, int size); | |
247 | extern int gen_rand_alphanumeric_plain(CephContext *cct, char *dest, int size); | |
248 | ||
249 | extern int gen_rand_alphanumeric_lower(CephContext *cct, string *str, int length); | |
250 | ||
251 | enum RGWIntentEvent { | |
252 | DEL_OBJ = 0, | |
253 | DEL_DIR = 1, | |
254 | }; | |
255 | ||
256 | enum RGWObjCategory { | |
257 | RGW_OBJ_CATEGORY_NONE = 0, | |
258 | RGW_OBJ_CATEGORY_MAIN = 1, | |
259 | RGW_OBJ_CATEGORY_SHADOW = 2, | |
260 | RGW_OBJ_CATEGORY_MULTIMETA = 3, | |
261 | }; | |
262 | ||
263 | /** Store error returns for output at a different point in the program */ | |
264 | struct rgw_err { | |
265 | rgw_err(); | |
266 | rgw_err(int http, const std::string &s3); | |
267 | void clear(); | |
268 | bool is_clear() const; | |
269 | bool is_err() const; | |
270 | friend std::ostream& operator<<(std::ostream& oss, const rgw_err &err); | |
271 | ||
272 | int http_ret; | |
273 | int ret; | |
274 | std::string s3_code; | |
275 | std::string message; | |
276 | }; | |
277 | ||
278 | /* Helper class used for RGWHTTPArgs parsing */ | |
279 | class NameVal | |
280 | { | |
281 | string str; | |
282 | string name; | |
283 | string val; | |
284 | public: | |
285 | explicit NameVal(string nv) : str(nv) {} | |
286 | ||
287 | int parse(); | |
288 | ||
289 | string& get_name() { return name; } | |
290 | string& get_val() { return val; } | |
291 | }; | |
292 | ||
293 | /** Stores the XML arguments associated with the HTTP request in req_state*/ | |
294 | class RGWHTTPArgs | |
295 | { | |
296 | string str, empty_str; | |
297 | map<string, string> val_map; | |
298 | map<string, string> sys_val_map; | |
299 | map<string, string> sub_resources; | |
300 | bool has_resp_modifier; | |
301 | bool admin_subresource_added; | |
302 | public: | |
303 | RGWHTTPArgs() : has_resp_modifier(false), admin_subresource_added(false) {} | |
304 | ||
305 | /** Set the arguments; as received */ | |
306 | void set(string s) { | |
307 | has_resp_modifier = false; | |
308 | val_map.clear(); | |
309 | sub_resources.clear(); | |
310 | str = s; | |
311 | } | |
312 | /** parse the received arguments */ | |
313 | int parse(); | |
314 | void append(const string& name, const string& val); | |
315 | /** Get the value for a specific argument parameter */ | |
316 | const string& get(const string& name, bool *exists = NULL) const; | |
317 | int get_bool(const string& name, bool *val, bool *exists); | |
318 | int get_bool(const char *name, bool *val, bool *exists); | |
319 | void get_bool(const char *name, bool *val, bool def_val); | |
320 | ||
321 | /** Get the value for specific system argument parameter */ | |
322 | std::string sys_get(const string& name, bool *exists = nullptr) const; | |
323 | ||
324 | /** see if a parameter is contained in this RGWHTTPArgs */ | |
325 | bool exists(const char *name) const { | |
326 | return (val_map.find(name) != std::end(val_map)); | |
327 | } | |
328 | bool sub_resource_exists(const char *name) const { | |
329 | return (sub_resources.find(name) != std::end(sub_resources)); | |
330 | } | |
331 | map<string, string>& get_params() { | |
332 | return val_map; | |
333 | } | |
334 | const std::map<std::string, std::string>& get_sub_resources() const { | |
335 | return sub_resources; | |
336 | } | |
337 | unsigned get_num_params() const { | |
338 | return val_map.size(); | |
339 | } | |
340 | bool has_response_modifier() const { | |
341 | return has_resp_modifier; | |
342 | } | |
343 | void set_system() { /* make all system params visible */ | |
344 | map<string, string>::iterator iter; | |
345 | for (iter = sys_val_map.begin(); iter != sys_val_map.end(); ++iter) { | |
346 | val_map[iter->first] = iter->second; | |
347 | } | |
348 | } | |
349 | const string& get_str() { | |
350 | return str; | |
351 | } | |
352 | }; | |
353 | ||
354 | class RGWEnv; | |
355 | ||
356 | class RGWConf { | |
357 | friend class RGWEnv; | |
358 | protected: | |
359 | void init(CephContext *cct, RGWEnv* env); | |
360 | public: | |
361 | RGWConf() | |
362 | : enable_ops_log(1), | |
363 | enable_usage_log(1), | |
364 | defer_to_bucket_acls(0) { | |
365 | } | |
366 | ||
367 | int enable_ops_log; | |
368 | int enable_usage_log; | |
369 | uint8_t defer_to_bucket_acls; | |
370 | }; | |
371 | ||
372 | class RGWEnv { | |
373 | std::map<string, string, ltstr_nocase> env_map; | |
374 | public: | |
375 | RGWConf conf; | |
376 | ||
377 | void init(CephContext *cct); | |
378 | void init(CephContext *cct, char **envp); | |
379 | void set(const boost::string_ref& name, const boost::string_ref& val); | |
380 | const char *get(const char *name, const char *def_val = NULL); | |
381 | int get_int(const char *name, int def_val = 0); | |
382 | bool get_bool(const char *name, bool def_val = 0); | |
383 | size_t get_size(const char *name, size_t def_val = 0); | |
384 | bool exists(const char *name); | |
385 | bool exists_prefix(const char *prefix); | |
386 | ||
387 | void remove(const char *name); | |
388 | ||
389 | std::map<string, string, ltstr_nocase>& get_map() { return env_map; } | |
390 | }; | |
391 | ||
392 | enum http_op { | |
393 | OP_GET, | |
394 | OP_PUT, | |
395 | OP_DELETE, | |
396 | OP_HEAD, | |
397 | OP_POST, | |
398 | OP_COPY, | |
399 | OP_OPTIONS, | |
400 | OP_UNKNOWN, | |
401 | }; | |
402 | ||
403 | enum RGWOpType { | |
404 | RGW_OP_UNKNOWN = 0, | |
405 | RGW_OP_GET_OBJ, | |
406 | RGW_OP_LIST_BUCKETS, | |
407 | RGW_OP_STAT_ACCOUNT, | |
408 | RGW_OP_LIST_BUCKET, | |
409 | RGW_OP_GET_BUCKET_LOGGING, | |
410 | RGW_OP_GET_BUCKET_VERSIONING, | |
411 | RGW_OP_SET_BUCKET_VERSIONING, | |
412 | RGW_OP_GET_BUCKET_WEBSITE, | |
413 | RGW_OP_SET_BUCKET_WEBSITE, | |
414 | RGW_OP_STAT_BUCKET, | |
415 | RGW_OP_CREATE_BUCKET, | |
416 | RGW_OP_DELETE_BUCKET, | |
417 | RGW_OP_PUT_OBJ, | |
418 | RGW_OP_STAT_OBJ, | |
419 | RGW_OP_POST_OBJ, | |
420 | RGW_OP_PUT_METADATA_ACCOUNT, | |
421 | RGW_OP_PUT_METADATA_BUCKET, | |
422 | RGW_OP_PUT_METADATA_OBJECT, | |
423 | RGW_OP_SET_TEMPURL, | |
424 | RGW_OP_DELETE_OBJ, | |
425 | RGW_OP_COPY_OBJ, | |
426 | RGW_OP_GET_ACLS, | |
427 | RGW_OP_PUT_ACLS, | |
428 | RGW_OP_GET_CORS, | |
429 | RGW_OP_PUT_CORS, | |
430 | RGW_OP_DELETE_CORS, | |
431 | RGW_OP_OPTIONS_CORS, | |
432 | RGW_OP_GET_REQUEST_PAYMENT, | |
433 | RGW_OP_SET_REQUEST_PAYMENT, | |
434 | RGW_OP_INIT_MULTIPART, | |
435 | RGW_OP_COMPLETE_MULTIPART, | |
436 | RGW_OP_ABORT_MULTIPART, | |
437 | RGW_OP_LIST_MULTIPART, | |
438 | RGW_OP_LIST_BUCKET_MULTIPARTS, | |
439 | RGW_OP_DELETE_MULTI_OBJ, | |
440 | RGW_OP_BULK_DELETE, | |
441 | RGW_OP_SET_ATTRS, | |
442 | RGW_OP_GET_CROSS_DOMAIN_POLICY, | |
443 | RGW_OP_GET_HEALTH_CHECK, | |
444 | RGW_OP_GET_INFO, | |
445 | RGW_OP_CREATE_ROLE, | |
446 | RGW_OP_DELETE_ROLE, | |
447 | RGW_OP_GET_ROLE, | |
448 | RGW_OP_MODIFY_ROLE, | |
449 | RGW_OP_LIST_ROLES, | |
450 | RGW_OP_PUT_ROLE_POLICY, | |
451 | RGW_OP_GET_ROLE_POLICY, | |
452 | RGW_OP_LIST_ROLE_POLICIES, | |
453 | RGW_OP_DELETE_ROLE_POLICY, | |
454 | ||
455 | /* rgw specific */ | |
456 | RGW_OP_ADMIN_SET_METADATA, | |
457 | RGW_OP_GET_OBJ_LAYOUT, | |
458 | ||
459 | RGW_OP_BULK_UPLOAD | |
460 | }; | |
461 | ||
462 | class RGWAccessControlPolicy; | |
463 | class JSONObj; | |
464 | ||
465 | struct RGWAccessKey { | |
466 | string id; // AccessKey | |
467 | string key; // SecretKey | |
468 | string subuser; | |
469 | ||
470 | RGWAccessKey() {} | |
471 | RGWAccessKey(std::string _id, std::string _key) | |
472 | : id(std::move(_id)), key(std::move(_key)) {} | |
473 | ||
474 | void encode(bufferlist& bl) const { | |
475 | ENCODE_START(2, 2, bl); | |
476 | ::encode(id, bl); | |
477 | ::encode(key, bl); | |
478 | ::encode(subuser, bl); | |
479 | ENCODE_FINISH(bl); | |
480 | } | |
481 | ||
482 | void decode(bufferlist::iterator& bl) { | |
483 | DECODE_START_LEGACY_COMPAT_LEN_32(2, 2, 2, bl); | |
484 | ::decode(id, bl); | |
485 | ::decode(key, bl); | |
486 | ::decode(subuser, bl); | |
487 | DECODE_FINISH(bl); | |
488 | } | |
489 | void dump(Formatter *f) const; | |
490 | void dump_plain(Formatter *f) const; | |
491 | void dump(Formatter *f, const string& user, bool swift) const; | |
492 | static void generate_test_instances(list<RGWAccessKey*>& o); | |
493 | ||
494 | void decode_json(JSONObj *obj); | |
495 | void decode_json(JSONObj *obj, bool swift); | |
496 | }; | |
497 | WRITE_CLASS_ENCODER(RGWAccessKey) | |
498 | ||
499 | struct RGWSubUser { | |
500 | string name; | |
501 | uint32_t perm_mask; | |
502 | ||
503 | RGWSubUser() : perm_mask(0) {} | |
504 | void encode(bufferlist& bl) const { | |
505 | ENCODE_START(2, 2, bl); | |
506 | ::encode(name, bl); | |
507 | ::encode(perm_mask, bl); | |
508 | ENCODE_FINISH(bl); | |
509 | } | |
510 | ||
511 | void decode(bufferlist::iterator& bl) { | |
512 | DECODE_START_LEGACY_COMPAT_LEN_32(2, 2, 2, bl); | |
513 | ::decode(name, bl); | |
514 | ::decode(perm_mask, bl); | |
515 | DECODE_FINISH(bl); | |
516 | } | |
517 | void dump(Formatter *f) const; | |
518 | void dump(Formatter *f, const string& user) const; | |
519 | static void generate_test_instances(list<RGWSubUser*>& o); | |
520 | ||
521 | void decode_json(JSONObj *obj); | |
522 | }; | |
523 | WRITE_CLASS_ENCODER(RGWSubUser) | |
524 | ||
525 | class RGWUserCaps | |
526 | { | |
527 | map<string, uint32_t> caps; | |
528 | ||
529 | int get_cap(const string& cap, string& type, uint32_t *perm); | |
530 | int add_cap(const string& cap); | |
531 | int remove_cap(const string& cap); | |
532 | public: | |
533 | static int parse_cap_perm(const string& str, uint32_t *perm); | |
534 | int add_from_string(const string& str); | |
535 | int remove_from_string(const string& str); | |
536 | ||
537 | void encode(bufferlist& bl) const { | |
538 | ENCODE_START(1, 1, bl); | |
539 | ::encode(caps, bl); | |
540 | ENCODE_FINISH(bl); | |
541 | } | |
542 | void decode(bufferlist::iterator& bl) { | |
543 | DECODE_START(1, bl); | |
544 | ::decode(caps, bl); | |
545 | DECODE_FINISH(bl); | |
546 | } | |
547 | int check_cap(const string& cap, uint32_t perm); | |
548 | bool is_valid_cap_type(const string& tp); | |
549 | void dump(Formatter *f) const; | |
550 | void dump(Formatter *f, const char *name) const; | |
551 | ||
552 | void decode_json(JSONObj *obj); | |
553 | }; | |
554 | WRITE_CLASS_ENCODER(RGWUserCaps) | |
555 | ||
556 | void encode_json(const char *name, const obj_version& v, Formatter *f); | |
557 | void encode_json(const char *name, const RGWUserCaps& val, Formatter *f); | |
558 | ||
559 | void decode_json_obj(obj_version& v, JSONObj *obj); | |
560 | ||
561 | enum RGWUserSourceType | |
562 | { | |
563 | TYPE_NONE=0, | |
564 | TYPE_RGW=1, | |
565 | TYPE_KEYSTONE=2, | |
566 | TYPE_LDAP=3 | |
567 | }; | |
568 | ||
569 | struct RGWUserInfo | |
570 | { | |
571 | uint64_t auid; | |
572 | rgw_user user_id; | |
573 | string display_name; | |
574 | string user_email; | |
575 | map<string, RGWAccessKey> access_keys; | |
576 | map<string, RGWAccessKey> swift_keys; | |
577 | map<string, RGWSubUser> subusers; | |
578 | __u8 suspended; | |
579 | int32_t max_buckets; | |
580 | uint32_t op_mask; | |
581 | RGWUserCaps caps; | |
582 | __u8 admin; | |
583 | __u8 system; | |
584 | string default_placement; | |
585 | list<string> placement_tags; | |
586 | RGWQuotaInfo bucket_quota; | |
587 | map<int, string> temp_url_keys; | |
588 | RGWQuotaInfo user_quota; | |
589 | uint32_t type; | |
590 | ||
591 | RGWUserInfo() | |
592 | : auid(0), | |
593 | suspended(0), | |
594 | max_buckets(RGW_DEFAULT_MAX_BUCKETS), | |
595 | op_mask(RGW_OP_TYPE_ALL), | |
596 | admin(0), | |
597 | system(0), | |
598 | type(TYPE_NONE) { | |
599 | } | |
600 | ||
601 | RGWAccessKey* get_key0() { | |
602 | if (access_keys.empty()) | |
603 | return nullptr; | |
604 | else | |
605 | return &(access_keys.begin()->second); | |
606 | } | |
607 | ||
608 | void encode(bufferlist& bl) const { | |
609 | ENCODE_START(19, 9, bl); | |
610 | ::encode(auid, bl); | |
611 | string access_key; | |
612 | string secret_key; | |
613 | if (!access_keys.empty()) { | |
614 | map<string, RGWAccessKey>::const_iterator iter = access_keys.begin(); | |
615 | const RGWAccessKey& k = iter->second; | |
616 | access_key = k.id; | |
617 | secret_key = k.key; | |
618 | } | |
619 | ::encode(access_key, bl); | |
620 | ::encode(secret_key, bl); | |
621 | ::encode(display_name, bl); | |
622 | ::encode(user_email, bl); | |
623 | string swift_name; | |
624 | string swift_key; | |
625 | if (!swift_keys.empty()) { | |
626 | map<string, RGWAccessKey>::const_iterator iter = swift_keys.begin(); | |
627 | const RGWAccessKey& k = iter->second; | |
628 | swift_name = k.id; | |
629 | swift_key = k.key; | |
630 | } | |
631 | ::encode(swift_name, bl); | |
632 | ::encode(swift_key, bl); | |
633 | ::encode(user_id.id, bl); | |
634 | ::encode(access_keys, bl); | |
635 | ::encode(subusers, bl); | |
636 | ::encode(suspended, bl); | |
637 | ::encode(swift_keys, bl); | |
638 | ::encode(max_buckets, bl); | |
639 | ::encode(caps, bl); | |
640 | ::encode(op_mask, bl); | |
641 | ::encode(system, bl); | |
642 | ::encode(default_placement, bl); | |
643 | ::encode(placement_tags, bl); | |
644 | ::encode(bucket_quota, bl); | |
645 | ::encode(temp_url_keys, bl); | |
646 | ::encode(user_quota, bl); | |
647 | ::encode(user_id.tenant, bl); | |
648 | ::encode(admin, bl); | |
649 | ::encode(type, bl); | |
650 | ENCODE_FINISH(bl); | |
651 | } | |
652 | void decode(bufferlist::iterator& bl) { | |
653 | DECODE_START_LEGACY_COMPAT_LEN_32(19, 9, 9, bl); | |
654 | if (struct_v >= 2) ::decode(auid, bl); | |
655 | else auid = CEPH_AUTH_UID_DEFAULT; | |
656 | string access_key; | |
657 | string secret_key; | |
658 | ::decode(access_key, bl); | |
659 | ::decode(secret_key, bl); | |
660 | if (struct_v < 6) { | |
661 | RGWAccessKey k; | |
662 | k.id = access_key; | |
663 | k.key = secret_key; | |
664 | access_keys[access_key] = k; | |
665 | } | |
666 | ::decode(display_name, bl); | |
667 | ::decode(user_email, bl); | |
668 | /* We populate swift_keys map later nowadays, but we have to decode. */ | |
669 | string swift_name; | |
670 | string swift_key; | |
671 | if (struct_v >= 3) ::decode(swift_name, bl); | |
672 | if (struct_v >= 4) ::decode(swift_key, bl); | |
673 | if (struct_v >= 5) | |
674 | ::decode(user_id.id, bl); | |
675 | else | |
676 | user_id.id = access_key; | |
677 | if (struct_v >= 6) { | |
678 | ::decode(access_keys, bl); | |
679 | ::decode(subusers, bl); | |
680 | } | |
681 | suspended = 0; | |
682 | if (struct_v >= 7) { | |
683 | ::decode(suspended, bl); | |
684 | } | |
685 | if (struct_v >= 8) { | |
686 | ::decode(swift_keys, bl); | |
687 | } | |
688 | if (struct_v >= 10) { | |
689 | ::decode(max_buckets, bl); | |
690 | } else { | |
691 | max_buckets = RGW_DEFAULT_MAX_BUCKETS; | |
692 | } | |
693 | if (struct_v >= 11) { | |
694 | ::decode(caps, bl); | |
695 | } | |
696 | if (struct_v >= 12) { | |
697 | ::decode(op_mask, bl); | |
698 | } else { | |
699 | op_mask = RGW_OP_TYPE_ALL; | |
700 | } | |
701 | if (struct_v >= 13) { | |
702 | ::decode(system, bl); | |
703 | ::decode(default_placement, bl); | |
704 | ::decode(placement_tags, bl); /* tags of allowed placement rules */ | |
705 | } | |
706 | if (struct_v >= 14) { | |
707 | ::decode(bucket_quota, bl); | |
708 | } | |
709 | if (struct_v >= 15) { | |
710 | ::decode(temp_url_keys, bl); | |
711 | } | |
712 | if (struct_v >= 16) { | |
713 | ::decode(user_quota, bl); | |
714 | } | |
715 | if (struct_v >= 17) { | |
716 | ::decode(user_id.tenant, bl); | |
717 | } else { | |
718 | user_id.tenant.clear(); | |
719 | } | |
720 | if (struct_v >= 18) { | |
721 | ::decode(admin, bl); | |
722 | } | |
723 | if (struct_v >= 19) { | |
724 | ::decode(type, bl); | |
725 | } | |
726 | DECODE_FINISH(bl); | |
727 | } | |
728 | void dump(Formatter *f) const; | |
729 | static void generate_test_instances(list<RGWUserInfo*>& o); | |
730 | ||
731 | void decode_json(JSONObj *obj); | |
732 | }; | |
733 | WRITE_CLASS_ENCODER(RGWUserInfo) | |
734 | ||
735 | struct rgw_pool { | |
736 | string name; | |
737 | string ns; | |
738 | ||
739 | rgw_pool() {} | |
740 | rgw_pool(const rgw_pool& _p) : name(_p.name), ns(_p.ns) {} | |
741 | rgw_pool(const string& _s) { | |
742 | from_str(_s); | |
743 | } | |
744 | rgw_pool(const string& _name, const string& _ns) : name(_name), ns(_ns) {} | |
745 | ||
746 | string to_str() const; | |
747 | void from_str(const string& s); | |
748 | ||
749 | void init(const string& _s) { | |
750 | from_str(_s); | |
751 | } | |
752 | ||
753 | bool empty() const { | |
754 | return name.empty(); | |
755 | } | |
756 | ||
757 | int compare(const rgw_pool& p) const { | |
758 | int r = name.compare(p.name); | |
759 | if (r != 0) { | |
760 | return r; | |
761 | } | |
762 | return ns.compare(p.ns); | |
763 | } | |
764 | ||
765 | void encode(bufferlist& bl) const { | |
766 | ENCODE_START(10, 10, bl); | |
767 | ::encode(name, bl); | |
768 | ::encode(ns, bl); | |
769 | ENCODE_FINISH(bl); | |
770 | } | |
771 | ||
772 | void decode_from_bucket(bufferlist::iterator& bl); | |
773 | ||
774 | void decode(bufferlist::iterator& bl) { | |
775 | DECODE_START_LEGACY_COMPAT_LEN(10, 3, 3, bl); | |
776 | ||
777 | ::decode(name, bl); | |
778 | ||
779 | if (struct_v < 10) { | |
780 | ||
781 | /* | |
782 | * note that rgw_pool can be used where rgw_bucket was used before | |
783 | * therefore we inherit rgw_bucket's old versions. However, we only | |
784 | * need the first field from rgw_bucket. unless we add more fields | |
785 | * in which case we'll need to look at struct_v, and check the actual | |
786 | * version. Anything older than 10 needs to be treated as old rgw_bucket | |
787 | */ | |
788 | ||
789 | } else { | |
790 | ::decode(ns, bl); | |
791 | } | |
792 | ||
793 | DECODE_FINISH(bl); | |
794 | } | |
795 | ||
796 | bool operator==(const rgw_pool& p) const { | |
797 | return (compare(p) == 0); | |
798 | } | |
799 | bool operator!=(const rgw_pool& p) const { | |
800 | return !(*this == p); | |
801 | } | |
802 | bool operator<(const rgw_pool& p) const { | |
803 | int r = name.compare(p.name); | |
804 | if (r == 0) { | |
805 | return (ns.compare(p.ns) < 0); | |
806 | } | |
807 | return (r < 0); | |
808 | } | |
809 | }; | |
810 | WRITE_CLASS_ENCODER(rgw_pool) | |
811 | ||
812 | struct rgw_data_placement_target { | |
813 | rgw_pool data_pool; | |
814 | rgw_pool data_extra_pool; | |
815 | rgw_pool index_pool; | |
816 | ||
817 | rgw_data_placement_target() {} | |
818 | ||
819 | rgw_data_placement_target(const rgw_pool& _data_pool, const rgw_pool& _data_extra_pool, const rgw_pool& _index_pool) | |
820 | : data_pool(_data_pool), data_extra_pool(_data_extra_pool), index_pool(_index_pool) {} | |
821 | ||
822 | const rgw_pool& get_data_extra_pool() const { | |
823 | if (data_extra_pool.empty()) { | |
824 | return data_pool; | |
825 | } | |
826 | return data_extra_pool; | |
827 | } | |
828 | ||
829 | int compare(const rgw_data_placement_target& t) { | |
830 | int c = data_pool.compare(t.data_pool); | |
831 | if (c != 0) { | |
832 | return c; | |
833 | } | |
834 | c = data_extra_pool.compare(t.data_extra_pool); | |
835 | if (c != 0) { | |
836 | return c; | |
837 | } | |
838 | return index_pool.compare(t.index_pool); | |
839 | }; | |
840 | ||
841 | void dump(Formatter *f) const; | |
842 | void decode_json(JSONObj *obj); | |
843 | }; | |
844 | ||
845 | inline ostream& operator<<(ostream& out, const rgw_pool& p) { | |
846 | out << p.to_str(); | |
847 | return out; | |
848 | } | |
849 | ||
850 | struct rgw_raw_obj { | |
851 | rgw_pool pool; | |
852 | std::string oid; | |
853 | std::string loc; | |
854 | ||
855 | rgw_raw_obj() {} | |
856 | rgw_raw_obj(const rgw_pool& _pool, const std::string& _oid) { | |
857 | init(_pool, _oid); | |
858 | } | |
859 | rgw_raw_obj(const rgw_pool& _pool, const std::string& _oid, const string& _loc) : loc(_loc) { | |
860 | init(_pool, _oid); | |
861 | } | |
862 | ||
863 | void init(const rgw_pool& _pool, const std::string& _oid) { | |
864 | pool = _pool; | |
865 | oid = _oid; | |
866 | } | |
867 | ||
868 | bool empty() const { | |
869 | return oid.empty(); | |
870 | } | |
871 | ||
872 | void encode(bufferlist& bl) const { | |
873 | ENCODE_START(6, 6, bl); | |
874 | ::encode(pool, bl); | |
875 | ::encode(oid, bl); | |
876 | ::encode(loc, bl); | |
877 | ENCODE_FINISH(bl); | |
878 | } | |
879 | ||
880 | void decode_from_rgw_obj(bufferlist::iterator& bl); | |
881 | ||
882 | void decode(bufferlist::iterator& bl) { | |
883 | unsigned ofs = bl.get_off(); | |
884 | DECODE_START(6, bl); | |
885 | if (struct_v < 6) { | |
886 | /* | |
887 | * this object was encoded as rgw_obj, prior to rgw_raw_obj been split out of it, | |
888 | * let's decode it as rgw_obj and convert it | |
889 | */ | |
890 | bl.seek(ofs); | |
891 | decode_from_rgw_obj(bl); | |
892 | return; | |
893 | } | |
894 | ::decode(pool, bl); | |
895 | ::decode(oid, bl); | |
896 | ::decode(loc, bl); | |
897 | DECODE_FINISH(bl); | |
898 | } | |
899 | ||
900 | bool operator<(const rgw_raw_obj& o) const { | |
901 | int r = pool.compare(o.pool); | |
902 | if (r == 0) { | |
903 | r = oid.compare(o.oid); | |
904 | if (r == 0) { | |
905 | r = loc.compare(o.loc); | |
906 | } | |
907 | } | |
908 | return (r < 0); | |
909 | } | |
910 | ||
911 | bool operator==(const rgw_raw_obj& o) const { | |
912 | return (pool == o.pool && oid == o.oid && loc == o.loc); | |
913 | } | |
914 | ||
915 | void dump(Formatter *f) const; | |
916 | void decode_json(JSONObj *obj); | |
917 | }; | |
918 | WRITE_CLASS_ENCODER(rgw_raw_obj) | |
919 | ||
920 | inline ostream& operator<<(ostream& out, const rgw_raw_obj& o) { | |
921 | out << o.pool << ":" << o.oid; | |
922 | return out; | |
923 | } | |
924 | ||
925 | struct rgw_bucket { | |
926 | std::string tenant; | |
927 | std::string name; | |
928 | std::string marker; | |
929 | std::string bucket_id; | |
930 | rgw_data_placement_target explicit_placement; | |
931 | ||
932 | std::string oid; /* | |
933 | * runtime in-memory only info. If not empty, points to the bucket instance object | |
934 | */ | |
935 | ||
936 | rgw_bucket() { } | |
937 | // cppcheck-suppress noExplicitConstructor | |
938 | explicit rgw_bucket(const rgw_user& u, const cls_user_bucket& b) : | |
939 | tenant(u.tenant), | |
940 | name(b.name), | |
941 | marker(b.marker), | |
942 | bucket_id(b.bucket_id), | |
943 | explicit_placement(b.explicit_placement.data_pool, | |
944 | b.explicit_placement.data_extra_pool, | |
945 | b.explicit_placement.index_pool) {} | |
946 | ||
947 | void convert(cls_user_bucket *b) const { | |
948 | b->name = name; | |
949 | b->marker = marker; | |
950 | b->bucket_id = bucket_id; | |
951 | b->explicit_placement.data_pool = explicit_placement.data_pool.to_str(); | |
952 | b->explicit_placement.data_extra_pool = explicit_placement.data_extra_pool.to_str(); | |
953 | b->explicit_placement.index_pool = explicit_placement.index_pool.to_str(); | |
954 | } | |
955 | ||
956 | void encode(bufferlist& bl) const { | |
957 | ENCODE_START(10, 10, bl); | |
958 | ::encode(name, bl); | |
959 | ::encode(marker, bl); | |
960 | ::encode(bucket_id, bl); | |
961 | ::encode(tenant, bl); | |
962 | bool encode_explicit = !explicit_placement.data_pool.empty(); | |
963 | ::encode(encode_explicit, bl); | |
964 | if (encode_explicit) { | |
965 | ::encode(explicit_placement.data_pool, bl); | |
966 | ::encode(explicit_placement.data_extra_pool, bl); | |
967 | ::encode(explicit_placement.index_pool, bl); | |
968 | } | |
969 | ENCODE_FINISH(bl); | |
970 | } | |
971 | void decode(bufferlist::iterator& bl) { | |
972 | DECODE_START_LEGACY_COMPAT_LEN(10, 3, 3, bl); | |
973 | ::decode(name, bl); | |
974 | if (struct_v < 10) { | |
975 | ::decode(explicit_placement.data_pool.name, bl); | |
976 | } | |
977 | if (struct_v >= 2) { | |
978 | ::decode(marker, bl); | |
979 | if (struct_v <= 3) { | |
980 | uint64_t id; | |
981 | ::decode(id, bl); | |
982 | char buf[16]; | |
983 | snprintf(buf, sizeof(buf), "%llu", (long long)id); | |
984 | bucket_id = buf; | |
985 | } else { | |
986 | ::decode(bucket_id, bl); | |
987 | } | |
988 | } | |
989 | if (struct_v < 10) { | |
990 | if (struct_v >= 5) { | |
991 | ::decode(explicit_placement.index_pool.name, bl); | |
992 | } else { | |
993 | explicit_placement.index_pool = explicit_placement.data_pool; | |
994 | } | |
995 | if (struct_v >= 7) { | |
996 | ::decode(explicit_placement.data_extra_pool.name, bl); | |
997 | } | |
998 | } | |
999 | if (struct_v >= 8) { | |
1000 | ::decode(tenant, bl); | |
1001 | } | |
1002 | if (struct_v >= 10) { | |
1003 | bool decode_explicit = !explicit_placement.data_pool.empty(); | |
1004 | ::decode(decode_explicit, bl); | |
1005 | if (decode_explicit) { | |
1006 | ::decode(explicit_placement.data_pool, bl); | |
1007 | ::decode(explicit_placement.data_extra_pool, bl); | |
1008 | ::decode(explicit_placement.index_pool, bl); | |
1009 | } | |
1010 | } | |
1011 | DECODE_FINISH(bl); | |
1012 | } | |
1013 | ||
1014 | // format a key for the bucket/instance. pass delim=0 to skip a field | |
1015 | std::string get_key(char tenant_delim = '/', | |
1016 | char id_delim = ':') const; | |
1017 | ||
1018 | const rgw_pool& get_data_extra_pool() const { | |
1019 | return explicit_placement.get_data_extra_pool(); | |
1020 | } | |
1021 | ||
1022 | void dump(Formatter *f) const; | |
1023 | void decode_json(JSONObj *obj); | |
1024 | static void generate_test_instances(list<rgw_bucket*>& o); | |
1025 | ||
1026 | bool operator<(const rgw_bucket& b) const { | |
1027 | return name.compare(b.name) < 0; | |
1028 | } | |
1029 | bool operator==(const rgw_bucket& b) const { | |
1030 | return (name == b.name) && (bucket_id == b.bucket_id); | |
1031 | } | |
1032 | }; | |
1033 | WRITE_CLASS_ENCODER(rgw_bucket) | |
1034 | ||
1035 | inline ostream& operator<<(ostream& out, const rgw_bucket &b) { | |
1036 | out << b.name << "[" << b.marker << "])"; | |
1037 | return out; | |
1038 | } | |
1039 | ||
1040 | struct rgw_bucket_shard { | |
1041 | rgw_bucket bucket; | |
1042 | int shard_id; | |
1043 | ||
1044 | rgw_bucket_shard() : shard_id(-1) {} | |
1045 | rgw_bucket_shard(const rgw_bucket& _b, int _sid) : bucket(_b), shard_id(_sid) {} | |
1046 | ||
1047 | std::string get_key(char tenant_delim = '/', char id_delim = ':', | |
1048 | char shard_delim = ':') const; | |
1049 | ||
1050 | bool operator<(const rgw_bucket_shard& b) const { | |
1051 | if (bucket < b.bucket) { | |
1052 | return true; | |
1053 | } | |
1054 | if (b.bucket < bucket) { | |
1055 | return false; | |
1056 | } | |
1057 | return shard_id < b.shard_id; | |
1058 | } | |
1059 | }; | |
1060 | ||
1061 | ||
1062 | struct RGWObjVersionTracker { | |
1063 | obj_version read_version; | |
1064 | obj_version write_version; | |
1065 | ||
1066 | obj_version *version_for_read() { | |
1067 | return &read_version; | |
1068 | } | |
1069 | ||
1070 | obj_version *version_for_write() { | |
1071 | if (write_version.ver == 0) | |
1072 | return NULL; | |
1073 | ||
1074 | return &write_version; | |
1075 | } | |
1076 | ||
1077 | obj_version *version_for_check() { | |
1078 | if (read_version.ver == 0) | |
1079 | return NULL; | |
1080 | ||
1081 | return &read_version; | |
1082 | } | |
1083 | ||
1084 | void prepare_op_for_read(librados::ObjectReadOperation *op); | |
1085 | void prepare_op_for_write(librados::ObjectWriteOperation *op); | |
1086 | ||
1087 | void apply_write() { | |
1088 | read_version = write_version; | |
1089 | write_version = obj_version(); | |
1090 | } | |
1091 | ||
1092 | void clear() { | |
1093 | read_version = obj_version(); | |
1094 | write_version = obj_version(); | |
1095 | } | |
1096 | ||
1097 | void generate_new_write_ver(CephContext *cct); | |
1098 | }; | |
1099 | ||
1100 | enum RGWBucketFlags { | |
1101 | BUCKET_SUSPENDED = 0x1, | |
1102 | BUCKET_VERSIONED = 0x2, | |
1103 | BUCKET_VERSIONS_SUSPENDED = 0x4, | |
1104 | }; | |
1105 | ||
1106 | enum RGWBucketIndexType { | |
1107 | RGWBIType_Normal = 0, | |
1108 | RGWBIType_Indexless = 1, | |
1109 | }; | |
1110 | ||
1111 | inline ostream& operator<<(ostream& out, const RGWBucketIndexType &index_type) | |
1112 | { | |
1113 | switch (index_type) { | |
1114 | case RGWBIType_Normal: | |
1115 | return out << "Normal"; | |
1116 | case RGWBIType_Indexless: | |
1117 | return out << "Indexless"; | |
1118 | default: | |
1119 | return out << "Unknown"; | |
1120 | } | |
1121 | } | |
1122 | ||
1123 | struct RGWBucketInfo | |
1124 | { | |
1125 | enum BIShardsHashType { | |
1126 | MOD = 0 | |
1127 | }; | |
1128 | ||
1129 | rgw_bucket bucket; | |
1130 | rgw_user owner; | |
1131 | uint32_t flags; | |
1132 | string zonegroup; | |
1133 | ceph::real_time creation_time; | |
1134 | string placement_rule; | |
1135 | bool has_instance_obj; | |
1136 | RGWObjVersionTracker objv_tracker; /* we don't need to serialize this, for runtime tracking */ | |
1137 | obj_version ep_objv; /* entry point object version, for runtime tracking only */ | |
1138 | RGWQuotaInfo quota; | |
1139 | ||
1140 | // Represents the number of bucket index object shards: | |
1141 | // - value of 0 indicates there is no sharding (this is by default before this | |
1142 | // feature is implemented). | |
1143 | // - value of UINT32_T::MAX indicates this is a blind bucket. | |
1144 | uint32_t num_shards; | |
1145 | ||
1146 | // Represents the bucket index shard hash type. | |
1147 | uint8_t bucket_index_shard_hash_type; | |
1148 | ||
1149 | // Represents the shard number for blind bucket. | |
1150 | const static uint32_t NUM_SHARDS_BLIND_BUCKET; | |
1151 | ||
1152 | bool requester_pays; | |
1153 | ||
1154 | bool has_website; | |
1155 | RGWBucketWebsiteConf website_conf; | |
1156 | ||
1157 | RGWBucketIndexType index_type; | |
1158 | ||
1159 | bool swift_versioning; | |
1160 | string swift_ver_location; | |
1161 | ||
1162 | ||
1163 | void encode(bufferlist& bl) const { | |
1164 | ENCODE_START(17, 4, bl); | |
1165 | ::encode(bucket, bl); | |
1166 | ::encode(owner.id, bl); | |
1167 | ::encode(flags, bl); | |
1168 | ::encode(zonegroup, bl); | |
1169 | uint64_t ct = real_clock::to_time_t(creation_time); | |
1170 | ::encode(ct, bl); | |
1171 | ::encode(placement_rule, bl); | |
1172 | ::encode(has_instance_obj, bl); | |
1173 | ::encode(quota, bl); | |
1174 | ::encode(num_shards, bl); | |
1175 | ::encode(bucket_index_shard_hash_type, bl); | |
1176 | ::encode(requester_pays, bl); | |
1177 | ::encode(owner.tenant, bl); | |
1178 | ::encode(has_website, bl); | |
1179 | if (has_website) { | |
1180 | ::encode(website_conf, bl); | |
1181 | } | |
1182 | ::encode((uint32_t)index_type, bl); | |
1183 | ::encode(swift_versioning, bl); | |
1184 | if (swift_versioning) { | |
1185 | ::encode(swift_ver_location, bl); | |
1186 | } | |
1187 | ::encode(creation_time, bl); | |
1188 | ENCODE_FINISH(bl); | |
1189 | } | |
1190 | void decode(bufferlist::iterator& bl) { | |
1191 | DECODE_START_LEGACY_COMPAT_LEN_32(17, 4, 4, bl); | |
1192 | ::decode(bucket, bl); | |
1193 | if (struct_v >= 2) { | |
1194 | string s; | |
1195 | ::decode(s, bl); | |
1196 | owner.from_str(s); | |
1197 | } | |
1198 | if (struct_v >= 3) | |
1199 | ::decode(flags, bl); | |
1200 | if (struct_v >= 5) | |
1201 | ::decode(zonegroup, bl); | |
1202 | if (struct_v >= 6) { | |
1203 | uint64_t ct; | |
1204 | ::decode(ct, bl); | |
1205 | if (struct_v < 17) | |
1206 | creation_time = ceph::real_clock::from_time_t((time_t)ct); | |
1207 | } | |
1208 | if (struct_v >= 7) | |
1209 | ::decode(placement_rule, bl); | |
1210 | if (struct_v >= 8) | |
1211 | ::decode(has_instance_obj, bl); | |
1212 | if (struct_v >= 9) | |
1213 | ::decode(quota, bl); | |
1214 | if (struct_v >= 10) | |
1215 | ::decode(num_shards, bl); | |
1216 | if (struct_v >= 11) | |
1217 | ::decode(bucket_index_shard_hash_type, bl); | |
1218 | if (struct_v >= 12) | |
1219 | ::decode(requester_pays, bl); | |
1220 | if (struct_v >= 13) | |
1221 | ::decode(owner.tenant, bl); | |
1222 | if (struct_v >= 14) { | |
1223 | ::decode(has_website, bl); | |
1224 | if (has_website) { | |
1225 | ::decode(website_conf, bl); | |
1226 | } else { | |
1227 | website_conf = RGWBucketWebsiteConf(); | |
1228 | } | |
1229 | } | |
1230 | if (struct_v >= 15) { | |
1231 | uint32_t it; | |
1232 | ::decode(it, bl); | |
1233 | index_type = (RGWBucketIndexType)it; | |
1234 | } else { | |
1235 | index_type = RGWBIType_Normal; | |
1236 | } | |
1237 | swift_versioning = false; | |
1238 | swift_ver_location.clear(); | |
1239 | if (struct_v >= 16) { | |
1240 | ::decode(swift_versioning, bl); | |
1241 | if (swift_versioning) { | |
1242 | ::decode(swift_ver_location, bl); | |
1243 | } | |
1244 | } | |
1245 | if (struct_v >= 17) { | |
1246 | ::decode(creation_time, bl); | |
1247 | } | |
1248 | DECODE_FINISH(bl); | |
1249 | } | |
1250 | void dump(Formatter *f) const; | |
1251 | static void generate_test_instances(list<RGWBucketInfo*>& o); | |
1252 | ||
1253 | void decode_json(JSONObj *obj); | |
1254 | ||
1255 | bool versioned() const { return (flags & BUCKET_VERSIONED) != 0; } | |
1256 | int versioning_status() { return flags & (BUCKET_VERSIONED | BUCKET_VERSIONS_SUSPENDED); } | |
1257 | bool versioning_enabled() { return versioning_status() == BUCKET_VERSIONED; } | |
1258 | ||
1259 | bool has_swift_versioning() const { | |
1260 | /* A bucket may be versioned through one mechanism only. */ | |
1261 | return swift_versioning && !versioned(); | |
1262 | } | |
1263 | ||
1264 | RGWBucketInfo() : flags(0), has_instance_obj(false), num_shards(0), bucket_index_shard_hash_type(MOD), requester_pays(false), | |
1265 | has_website(false), swift_versioning(false) {} | |
1266 | }; | |
1267 | WRITE_CLASS_ENCODER(RGWBucketInfo) | |
1268 | ||
1269 | struct RGWBucketEntryPoint | |
1270 | { | |
1271 | rgw_bucket bucket; | |
1272 | rgw_user owner; | |
1273 | ceph::real_time creation_time; | |
1274 | bool linked; | |
1275 | ||
1276 | bool has_bucket_info; | |
1277 | RGWBucketInfo old_bucket_info; | |
1278 | ||
1279 | RGWBucketEntryPoint() : linked(false), has_bucket_info(false) {} | |
1280 | ||
1281 | void encode(bufferlist& bl) const { | |
1282 | ENCODE_START(10, 8, bl); | |
1283 | ::encode(bucket, bl); | |
1284 | ::encode(owner.id, bl); | |
1285 | ::encode(linked, bl); | |
1286 | uint64_t ctime = (uint64_t)real_clock::to_time_t(creation_time); | |
1287 | ::encode(ctime, bl); | |
1288 | ::encode(owner, bl); | |
1289 | ::encode(creation_time, bl); | |
1290 | ENCODE_FINISH(bl); | |
1291 | } | |
1292 | void decode(bufferlist::iterator& bl) { | |
1293 | bufferlist::iterator orig_iter = bl; | |
1294 | DECODE_START_LEGACY_COMPAT_LEN_32(10, 4, 4, bl); | |
1295 | if (struct_v < 8) { | |
1296 | /* ouch, old entry, contains the bucket info itself */ | |
1297 | old_bucket_info.decode(orig_iter); | |
1298 | has_bucket_info = true; | |
1299 | return; | |
1300 | } | |
1301 | has_bucket_info = false; | |
1302 | ::decode(bucket, bl); | |
1303 | ::decode(owner.id, bl); | |
1304 | ::decode(linked, bl); | |
1305 | uint64_t ctime; | |
1306 | ::decode(ctime, bl); | |
1307 | if (struct_v < 10) { | |
1308 | creation_time = real_clock::from_time_t((time_t)ctime); | |
1309 | } | |
1310 | if (struct_v >= 9) { | |
1311 | ::decode(owner, bl); | |
1312 | } | |
1313 | if (struct_v >= 10) { | |
1314 | ::decode(creation_time, bl); | |
1315 | } | |
1316 | DECODE_FINISH(bl); | |
1317 | } | |
1318 | ||
1319 | void dump(Formatter *f) const; | |
1320 | void decode_json(JSONObj *obj); | |
1321 | }; | |
1322 | WRITE_CLASS_ENCODER(RGWBucketEntryPoint) | |
1323 | ||
1324 | struct RGWStorageStats | |
1325 | { | |
1326 | RGWObjCategory category; | |
1327 | uint64_t size; | |
1328 | uint64_t size_rounded; | |
1329 | uint64_t size_utilized{0}; //< size after compression, encryption | |
1330 | uint64_t num_objects; | |
1331 | ||
1332 | RGWStorageStats() | |
1333 | : category(RGW_OBJ_CATEGORY_NONE), | |
1334 | size(0), | |
1335 | size_rounded(0), | |
1336 | num_objects(0) {} | |
1337 | ||
1338 | void dump(Formatter *f) const; | |
1339 | }; | |
1340 | ||
1341 | struct req_state; | |
1342 | ||
1343 | class RGWEnv; | |
1344 | ||
1345 | /* Namespaced forward declarations. */ | |
1346 | namespace rgw { | |
1347 | namespace auth { | |
1348 | namespace s3 { | |
1349 | class RGWGetPolicyV2Extractor; | |
1350 | } | |
1351 | } | |
1352 | namespace io { | |
1353 | class BasicClient; | |
1354 | } | |
1355 | } | |
1356 | ||
1357 | struct req_info { | |
1358 | RGWEnv *env; | |
1359 | RGWHTTPArgs args; | |
1360 | map<string, string> x_meta_map; | |
1361 | ||
1362 | string host; | |
1363 | const char *method; | |
1364 | string script_uri; | |
1365 | string request_uri; | |
1366 | string request_uri_aws4; | |
1367 | string effective_uri; | |
1368 | string request_params; | |
1369 | string domain; | |
1370 | ||
1371 | req_info(CephContext *cct, RGWEnv *_env); | |
1372 | void rebuild_from(req_info& src); | |
1373 | void init_meta_info(bool *found_bad_meta); | |
1374 | }; | |
1375 | ||
1376 | typedef cls_rgw_obj_key rgw_obj_index_key; | |
1377 | ||
1378 | struct rgw_obj_key { | |
1379 | string name; | |
1380 | string instance; | |
1381 | string ns; | |
1382 | ||
1383 | rgw_obj_key() {} | |
1384 | // cppcheck-suppress noExplicitConstructor | |
1385 | rgw_obj_key(const string& n) : name(n) {} | |
1386 | rgw_obj_key(const string& n, const string& i) : name(n), instance(i) {} | |
1387 | rgw_obj_key(const string& n, const string& i, const string& _ns) : name(n), instance(i), ns(_ns) {} | |
1388 | ||
1389 | rgw_obj_key(const rgw_obj_index_key& k) { | |
1390 | parse_index_key(k.name, &name, &ns); | |
1391 | instance = k.instance; | |
1392 | } | |
1393 | ||
1394 | static void parse_index_key(const string& key, string *name, string *ns) { | |
1395 | if (key[0] != '_') { | |
1396 | *name = key; | |
1397 | ns->clear(); | |
1398 | return; | |
1399 | } | |
1400 | if (key[1] == '_') { | |
1401 | *name = key.substr(1); | |
1402 | ns->clear(); | |
1403 | return; | |
1404 | } | |
1405 | ssize_t pos = key.find('_', 1); | |
1406 | if (pos < 0) { | |
1407 | /* shouldn't happen, just use key */ | |
1408 | *name = key; | |
1409 | ns->clear(); | |
1410 | return; | |
1411 | } | |
1412 | ||
1413 | *name = key.substr(pos + 1); | |
1414 | *ns = key.substr(1, pos -1); | |
1415 | } | |
1416 | ||
1417 | void set(const string& n) { | |
1418 | name = n; | |
1419 | instance.clear(); | |
1420 | ns.clear(); | |
1421 | } | |
1422 | ||
1423 | void set(const string& n, const string& i) { | |
1424 | name = n; | |
1425 | instance = i; | |
1426 | ns.clear(); | |
1427 | } | |
1428 | ||
1429 | void set(const string& n, const string& i, const string& _ns) { | |
1430 | name = n; | |
1431 | instance = i; | |
1432 | ns = _ns; | |
1433 | } | |
1434 | ||
1435 | bool set(const rgw_obj_index_key& index_key) { | |
1436 | if (!parse_raw_oid(index_key.name, this)) { | |
1437 | return false; | |
1438 | } | |
1439 | instance = index_key.instance; | |
1440 | return true; | |
1441 | } | |
1442 | ||
1443 | void set_instance(const string& i) { | |
1444 | instance = i; | |
1445 | } | |
1446 | ||
1447 | string get_index_key_name() const { | |
1448 | if (ns.empty()) { | |
1449 | if (name.size() < 1 || name[0] != '_') { | |
1450 | return name; | |
1451 | } | |
1452 | return string("_") + name; | |
1453 | }; | |
1454 | ||
1455 | char buf[ns.size() + 16]; | |
1456 | snprintf(buf, sizeof(buf), "_%s_", ns.c_str()); | |
1457 | return string(buf) + name; | |
1458 | }; | |
1459 | ||
1460 | void get_index_key(rgw_obj_index_key *key) const { | |
1461 | key->name = get_index_key_name(); | |
1462 | key->instance = instance; | |
1463 | } | |
1464 | ||
1465 | string get_loc() const { | |
1466 | /* | |
1467 | * For backward compatibility. Older versions used to have object locator on all objects, | |
1468 | * however, the name was the effective object locator. This had the same effect as not | |
1469 | * having object locator at all for most objects but the ones that started with underscore as | |
1470 | * these were escaped. | |
1471 | */ | |
1472 | if (name[0] == '_' && ns.empty()) { | |
1473 | return name; | |
1474 | } | |
1475 | ||
1476 | return string(); | |
1477 | } | |
1478 | ||
1479 | bool empty() const { | |
1480 | return name.empty(); | |
1481 | } | |
1482 | ||
1483 | bool have_null_instance() const { | |
1484 | return instance == "null"; | |
1485 | } | |
1486 | ||
1487 | bool have_instance() const { | |
1488 | return !instance.empty(); | |
1489 | } | |
1490 | ||
1491 | bool need_to_encode_instance() const { | |
1492 | return have_instance() && !have_null_instance(); | |
1493 | } | |
1494 | ||
1495 | string get_oid() const { | |
1496 | if (ns.empty() && !need_to_encode_instance()) { | |
1497 | if (name.size() < 1 || name[0] != '_') { | |
1498 | return name; | |
1499 | } | |
1500 | return string("_") + name; | |
1501 | } | |
1502 | ||
1503 | string oid = "_"; | |
1504 | oid.append(ns); | |
1505 | if (need_to_encode_instance()) { | |
1506 | oid.append(string(":") + instance); | |
1507 | } | |
1508 | oid.append("_"); | |
1509 | oid.append(name); | |
1510 | return oid; | |
1511 | } | |
1512 | ||
1513 | bool operator==(const rgw_obj_key& k) const { | |
1514 | return (name.compare(k.name) == 0) && | |
1515 | (instance.compare(k.instance) == 0); | |
1516 | } | |
1517 | ||
1518 | bool operator<(const rgw_obj_key& k) const { | |
1519 | int r = name.compare(k.name); | |
1520 | if (r == 0) { | |
1521 | r = instance.compare(k.instance); | |
1522 | } | |
1523 | return (r < 0); | |
1524 | } | |
1525 | ||
1526 | bool operator<=(const rgw_obj_key& k) const { | |
1527 | return !(k < *this); | |
1528 | } | |
1529 | ||
1530 | static void parse_ns_field(string& ns, string& instance) { | |
1531 | int pos = ns.find(':'); | |
1532 | if (pos >= 0) { | |
1533 | instance = ns.substr(pos + 1); | |
1534 | ns = ns.substr(0, pos); | |
1535 | } else { | |
1536 | instance.clear(); | |
1537 | } | |
1538 | } | |
1539 | ||
1540 | static bool parse_raw_oid(const string& oid, rgw_obj_key *key) { | |
1541 | key->instance.clear(); | |
1542 | key->ns.clear(); | |
1543 | if (oid[0] != '_') { | |
1544 | key->name = oid; | |
1545 | return true; | |
1546 | } | |
1547 | ||
1548 | if (oid.size() >= 2 && oid[1] == '_') { | |
1549 | key->name = oid.substr(1); | |
1550 | return true; | |
1551 | } | |
1552 | ||
1553 | if (oid[0] != '_' || oid.size() < 3) // for namespace, min size would be 3: _x_ | |
1554 | return false; | |
1555 | ||
1556 | int pos = oid.find('_', 1); | |
1557 | if (pos <= 1) // if it starts with __, it's not in our namespace | |
1558 | return false; | |
1559 | ||
1560 | key->ns = oid.substr(1, pos - 1); | |
1561 | parse_ns_field(key->ns, key->instance); | |
1562 | ||
1563 | key->name = oid.substr(pos + 1); | |
1564 | return true; | |
1565 | } | |
1566 | ||
1567 | /** | |
1568 | * Translate a namespace-mangled object name to the user-facing name | |
1569 | * existing in the given namespace. | |
1570 | * | |
1571 | * If the object is part of the given namespace, it returns true | |
1572 | * and cuts down the name to the unmangled version. If it is not | |
1573 | * part of the given namespace, it returns false. | |
1574 | */ | |
1575 | static bool oid_to_key_in_ns(const string& oid, rgw_obj_key *key, const string& ns) { | |
1576 | string obj_ns; | |
1577 | bool ret = parse_raw_oid(oid, key); | |
1578 | if (!ret) { | |
1579 | return ret; | |
1580 | } | |
1581 | ||
1582 | return (ns == key->ns); | |
1583 | } | |
1584 | ||
1585 | /** | |
1586 | * Given a mangled object name and an empty namespace string, this | |
1587 | * function extracts the namespace into the string and sets the object | |
1588 | * name to be the unmangled version. | |
1589 | * | |
1590 | * It returns true after successfully doing so, or | |
1591 | * false if it fails. | |
1592 | */ | |
1593 | static bool strip_namespace_from_name(string& name, string& ns, string& instance) { | |
1594 | ns.clear(); | |
1595 | instance.clear(); | |
1596 | if (name[0] != '_') { | |
1597 | return true; | |
1598 | } | |
1599 | ||
1600 | size_t pos = name.find('_', 1); | |
1601 | if (pos == string::npos) { | |
1602 | return false; | |
1603 | } | |
1604 | ||
1605 | if (name[1] == '_') { | |
1606 | name = name.substr(1); | |
1607 | return true; | |
1608 | } | |
1609 | ||
1610 | size_t period_pos = name.find('.'); | |
1611 | if (period_pos < pos) { | |
1612 | return false; | |
1613 | } | |
1614 | ||
1615 | ns = name.substr(1, pos-1); | |
1616 | name = name.substr(pos+1, string::npos); | |
1617 | ||
1618 | parse_ns_field(ns, instance); | |
1619 | return true; | |
1620 | } | |
1621 | ||
1622 | void encode(bufferlist& bl) const { | |
1623 | ENCODE_START(2, 1, bl); | |
1624 | ::encode(name, bl); | |
1625 | ::encode(instance, bl); | |
1626 | ::encode(ns, bl); | |
1627 | ENCODE_FINISH(bl); | |
1628 | } | |
1629 | void decode(bufferlist::iterator& bl) { | |
1630 | DECODE_START(2, bl); | |
1631 | ::decode(name, bl); | |
1632 | ::decode(instance, bl); | |
1633 | if (struct_v >= 2) { | |
1634 | ::decode(ns, bl); | |
1635 | } | |
1636 | DECODE_FINISH(bl); | |
1637 | } | |
1638 | void dump(Formatter *f) const; | |
1639 | }; | |
1640 | WRITE_CLASS_ENCODER(rgw_obj_key) | |
1641 | ||
1642 | inline ostream& operator<<(ostream& out, const rgw_obj_key &o) { | |
1643 | if (o.instance.empty()) { | |
1644 | return out << o.name; | |
1645 | } else { | |
1646 | return out << o.name << "[" << o.instance << "]"; | |
1647 | } | |
1648 | } | |
1649 | ||
1650 | inline ostream& operator<<(ostream& out, const rgw_obj_index_key &o) { | |
1651 | if (o.instance.empty()) { | |
1652 | return out << o.name; | |
1653 | } else { | |
1654 | return out << o.name << "[" << o.instance << "]"; | |
1655 | } | |
1656 | } | |
1657 | ||
1658 | struct rgw_aws4_auth { | |
1659 | string date; | |
1660 | string expires; | |
1661 | string credential; | |
1662 | string signedheaders; | |
1663 | string signed_hdrs; | |
1664 | string access_key_id; | |
1665 | string credential_scope; | |
1666 | string canonical_uri; | |
1667 | string canonical_qs; | |
1668 | string canonical_hdrs; | |
1669 | string signature; | |
1670 | string new_signature; | |
1671 | string payload_hash; | |
1672 | string seed_signature; | |
1673 | string signing_key; | |
1674 | char signing_k[CEPH_CRYPTO_HMACSHA256_DIGESTSIZE]; | |
1675 | bufferlist bl; | |
1676 | }; | |
1677 | ||
1678 | struct req_init_state { | |
1679 | /* Keeps [[tenant]:]bucket until we parse the token. */ | |
1680 | string url_bucket; | |
1681 | string src_bucket; | |
1682 | }; | |
1683 | ||
1684 | /* XXX why don't RGWRequest (or descendants) hold this state? */ | |
1685 | class RGWRequest; | |
1686 | ||
1687 | #include "rgw_auth.h" | |
1688 | ||
1689 | /** Store all the state necessary to complete and respond to an HTTP request*/ | |
1690 | struct req_state { | |
1691 | CephContext *cct; | |
1692 | rgw::io::BasicClient *cio; | |
1693 | RGWRequest *req; /// XXX: re-remove?? | |
1694 | http_op op; | |
1695 | RGWOpType op_type; | |
1696 | bool content_started; | |
1697 | int format; | |
1698 | ceph::Formatter *formatter; | |
1699 | string decoded_uri; | |
1700 | string relative_uri; | |
1701 | const char *length; | |
1702 | int64_t content_length; | |
1703 | map<string, string> generic_attrs; | |
1704 | struct rgw_err err; | |
1705 | bool expect_cont; | |
1706 | bool header_ended; | |
1707 | uint64_t obj_size; | |
1708 | bool enable_ops_log; | |
1709 | bool enable_usage_log; | |
1710 | uint8_t defer_to_bucket_acls; | |
1711 | uint32_t perm_mask; | |
1712 | ||
1713 | /* Set once when url_bucket is parsed and not violated thereafter. */ | |
1714 | string account_name; | |
1715 | ||
1716 | string bucket_tenant; | |
1717 | string bucket_name; | |
1718 | ||
1719 | rgw_bucket bucket; | |
1720 | rgw_obj_key object; | |
1721 | string src_tenant_name; | |
1722 | string src_bucket_name; | |
1723 | rgw_obj_key src_object; | |
1724 | ACLOwner bucket_owner; | |
1725 | ACLOwner owner; | |
1726 | ||
1727 | string zonegroup_name; | |
1728 | string zonegroup_endpoint; | |
1729 | string bucket_instance_id; | |
1730 | int bucket_instance_shard_id; | |
1731 | ||
1732 | string redirect; | |
1733 | ||
1734 | RGWBucketInfo bucket_info; | |
1735 | map<string, bufferlist> bucket_attrs; | |
1736 | bool bucket_exists; | |
1737 | ||
1738 | bool has_bad_meta; | |
1739 | ||
1740 | RGWUserInfo *user; | |
1741 | ||
1742 | struct { | |
1743 | /* TODO(rzarzynski): switch out to the static_ptr for both members. */ | |
1744 | ||
1745 | /* Object having the knowledge about an authenticated identity and allowing | |
1746 | * to apply it during the authorization phase (verify_permission() methods | |
1747 | * of a given RGWOp). Thus, it bounds authentication and authorization steps | |
1748 | * through a well-defined interface. For more details, see rgw_auth.h. */ | |
1749 | std::unique_ptr<rgw::auth::Identity> identity; | |
1750 | ||
1751 | std::unique_ptr<rgw::auth::Completer> completer; | |
1752 | ||
1753 | /* A container for credentials of the S3's browser upload. It's necessary | |
1754 | * because: 1) the ::authenticate() method of auth engines and strategies | |
1755 | * take req_state only; 2) auth strategies live much longer than RGWOps - | |
1756 | * there is no way to pass additional data dependencies through ctors. */ | |
1757 | class { | |
1758 | /* Writer. */ | |
1759 | friend class RGWPostObj_ObjStore_S3; | |
1760 | /* Reader. */ | |
1761 | friend class rgw::auth::s3::RGWGetPolicyV2Extractor; | |
1762 | ||
1763 | std::string access_key; | |
1764 | std::string signature; | |
1765 | ceph::bufferlist encoded_policy; | |
1766 | } s3_postobj_creds; | |
1767 | } auth; | |
1768 | ||
1769 | std::unique_ptr<RGWAccessControlPolicy> user_acl; | |
1770 | RGWAccessControlPolicy *bucket_acl; | |
1771 | RGWAccessControlPolicy *object_acl; | |
1772 | ||
1773 | /* Is the request made by an user marked as a system one? | |
1774 | * Being system user means we also have the admin status. */ | |
1775 | bool system_request; | |
1776 | ||
1777 | /* aws4 auth support */ | |
1778 | bool aws4_auth_needs_complete; | |
1779 | bool aws4_auth_streaming_mode; | |
1780 | unique_ptr<rgw_aws4_auth> aws4_auth; | |
1781 | ||
1782 | string canned_acl; | |
1783 | bool has_acl_header; | |
1784 | const char *http_auth; | |
1785 | bool local_source; /* source is local */ | |
1786 | ||
1787 | int prot_flags; | |
1788 | ||
1789 | /* Content-Disposition override for TempURL of Swift API. */ | |
1790 | struct { | |
1791 | string override; | |
1792 | string fallback; | |
1793 | } content_disp; | |
1794 | ||
1795 | string host_id; | |
1796 | ||
1797 | req_info info; | |
1798 | req_init_state init_state; | |
1799 | ||
1800 | utime_t time; | |
1801 | void *obj_ctx; | |
1802 | string dialect; | |
1803 | string req_id; | |
1804 | string trans_id; | |
1805 | ||
1806 | req_state(CephContext* _cct, RGWEnv* e, RGWUserInfo* u); | |
1807 | ~req_state(); | |
1808 | }; | |
1809 | ||
1810 | /** Store basic data on bucket */ | |
1811 | struct RGWBucketEnt { | |
1812 | rgw_bucket bucket; | |
1813 | size_t size; | |
1814 | size_t size_rounded; | |
1815 | real_time creation_time; | |
1816 | uint64_t count; | |
1817 | ||
1818 | RGWBucketEnt() : size(0), size_rounded(0), count(0) {} | |
1819 | ||
1820 | explicit RGWBucketEnt(const rgw_user& u, const cls_user_bucket_entry& e) | |
1821 | : bucket(u, e.bucket), | |
1822 | size(e.size), | |
1823 | size_rounded(e.size_rounded), | |
1824 | creation_time(e.creation_time), | |
1825 | count(e.count) { | |
1826 | } | |
1827 | ||
1828 | void convert(cls_user_bucket_entry *b) const { | |
1829 | bucket.convert(&b->bucket); | |
1830 | b->size = size; | |
1831 | b->size_rounded = size_rounded; | |
1832 | b->creation_time = creation_time; | |
1833 | b->count = count; | |
1834 | } | |
1835 | ||
1836 | void encode(bufferlist& bl) const { | |
1837 | ENCODE_START(6, 5, bl); | |
1838 | uint64_t s = size; | |
1839 | __u32 mt = ceph::real_clock::to_time_t(creation_time); | |
1840 | string empty_str; // originally had the bucket name here, but we encode bucket later | |
1841 | ::encode(empty_str, bl); | |
1842 | ::encode(s, bl); | |
1843 | ::encode(mt, bl); | |
1844 | ::encode(count, bl); | |
1845 | ::encode(bucket, bl); | |
1846 | s = size_rounded; | |
1847 | ::encode(s, bl); | |
1848 | ::encode(creation_time, bl); | |
1849 | ENCODE_FINISH(bl); | |
1850 | } | |
1851 | void decode(bufferlist::iterator& bl) { | |
1852 | DECODE_START_LEGACY_COMPAT_LEN(6, 5, 5, bl); | |
1853 | __u32 mt; | |
1854 | uint64_t s; | |
1855 | string empty_str; // backward compatibility | |
1856 | ::decode(empty_str, bl); | |
1857 | ::decode(s, bl); | |
1858 | ::decode(mt, bl); | |
1859 | size = s; | |
1860 | if (struct_v < 6) { | |
1861 | creation_time = ceph::real_clock::from_time_t(mt); | |
1862 | } | |
1863 | if (struct_v >= 2) | |
1864 | ::decode(count, bl); | |
1865 | if (struct_v >= 3) | |
1866 | ::decode(bucket, bl); | |
1867 | if (struct_v >= 4) | |
1868 | ::decode(s, bl); | |
1869 | size_rounded = s; | |
1870 | if (struct_v >= 6) | |
1871 | ::decode(creation_time, bl); | |
1872 | DECODE_FINISH(bl); | |
1873 | } | |
1874 | void dump(Formatter *f) const; | |
1875 | static void generate_test_instances(list<RGWBucketEnt*>& o); | |
1876 | }; | |
1877 | WRITE_CLASS_ENCODER(RGWBucketEnt) | |
1878 | ||
1879 | struct rgw_obj { | |
1880 | rgw_bucket bucket; | |
1881 | rgw_obj_key key; | |
1882 | ||
1883 | bool in_extra_data{false}; /* in-memory only member, does not serialize */ | |
1884 | ||
1885 | // Represents the hash index source for this object once it is set (non-empty) | |
1886 | std::string index_hash_source; | |
1887 | ||
1888 | rgw_obj() {} | |
1889 | rgw_obj(const rgw_bucket& b, const std::string& name) : bucket(b), key(name) {} | |
1890 | rgw_obj(const rgw_bucket& b, const rgw_obj_key& k) : bucket(b), key(k) {} | |
1891 | rgw_obj(const rgw_bucket& b, const rgw_obj_index_key& k) : bucket(b), key(k) {} | |
1892 | ||
1893 | void init(const rgw_bucket& b, const std::string& name) { | |
1894 | bucket = b; | |
1895 | key.set(name); | |
1896 | } | |
1897 | void init(const rgw_bucket& b, const std::string& name, const string& i, const string& n) { | |
1898 | bucket = b; | |
1899 | key.set(name, i, n); | |
1900 | } | |
1901 | void init_ns(const rgw_bucket& b, const std::string& name, const string& n) { | |
1902 | bucket = b; | |
1903 | key.name = name; | |
1904 | key.instance.clear(); | |
1905 | key.ns = n; | |
1906 | } | |
1907 | ||
1908 | bool empty() const { | |
1909 | return key.empty(); | |
1910 | } | |
1911 | ||
1912 | void set_key(const rgw_obj_key& k) { | |
1913 | key = k; | |
1914 | } | |
1915 | ||
1916 | string get_oid() const { | |
1917 | return key.get_oid(); | |
1918 | } | |
1919 | ||
1920 | const string& get_hash_object() const { | |
1921 | return index_hash_source.empty() ? key.name : index_hash_source; | |
1922 | } | |
1923 | ||
1924 | void set_in_extra_data(bool val) { | |
1925 | in_extra_data = val; | |
1926 | } | |
1927 | ||
1928 | bool is_in_extra_data() const { | |
1929 | return in_extra_data; | |
1930 | } | |
1931 | ||
1932 | void encode(bufferlist& bl) const { | |
1933 | ENCODE_START(6, 6, bl); | |
1934 | ::encode(bucket, bl); | |
1935 | ::encode(key.ns, bl); | |
1936 | ::encode(key.name, bl); | |
1937 | ::encode(key.instance, bl); | |
1938 | // ::encode(placement_id, bl); | |
1939 | ENCODE_FINISH(bl); | |
1940 | } | |
1941 | void decode(bufferlist::iterator& bl) { | |
1942 | DECODE_START_LEGACY_COMPAT_LEN(6, 3, 3, bl); | |
1943 | if (struct_v < 6) { | |
1944 | string s; | |
1945 | ::decode(bucket.name, bl); /* bucket.name */ | |
1946 | ::decode(s, bl); /* loc */ | |
1947 | ::decode(key.ns, bl); | |
1948 | ::decode(key.name, bl); | |
1949 | if (struct_v >= 2) | |
1950 | ::decode(bucket, bl); | |
1951 | if (struct_v >= 4) | |
1952 | ::decode(key.instance, bl); | |
1953 | if (key.ns.empty() && key.instance.empty()) { | |
1954 | if (key.name[0] == '_') { | |
1955 | key.name = key.name.substr(1); | |
1956 | } | |
1957 | } else { | |
1958 | if (struct_v >= 5) { | |
1959 | ::decode(key.name, bl); | |
1960 | } else { | |
1961 | ssize_t pos = key.name.find('_', 1); | |
1962 | if (pos < 0) { | |
1963 | throw buffer::error(); | |
1964 | } | |
1965 | key.name = key.name.substr(pos); | |
1966 | } | |
1967 | } | |
1968 | } else { | |
1969 | ::decode(bucket, bl); | |
1970 | ::decode(key.ns, bl); | |
1971 | ::decode(key.name, bl); | |
1972 | ::decode(key.instance, bl); | |
1973 | // ::decode(placement_id, bl); | |
1974 | } | |
1975 | DECODE_FINISH(bl); | |
1976 | } | |
1977 | void dump(Formatter *f) const; | |
1978 | static void generate_test_instances(list<rgw_obj*>& o); | |
1979 | ||
1980 | bool operator==(const rgw_obj& o) const { | |
1981 | return (key == o.key) && | |
1982 | (bucket == o.bucket); | |
1983 | } | |
1984 | bool operator<(const rgw_obj& o) const { | |
1985 | int r = key.name.compare(o.key.name); | |
1986 | if (r == 0) { | |
1987 | r = bucket.bucket_id.compare(o.bucket.bucket_id); /* not comparing bucket.name, if bucket_id is equal so will be bucket.name */ | |
1988 | if (r == 0) { | |
1989 | r = key.ns.compare(o.key.ns); | |
1990 | if (r == 0) { | |
1991 | r = key.instance.compare(o.key.instance); | |
1992 | } | |
1993 | } | |
1994 | } | |
1995 | ||
1996 | return (r < 0); | |
1997 | } | |
1998 | ||
1999 | const rgw_pool& get_explicit_data_pool() { | |
2000 | if (!in_extra_data || bucket.explicit_placement.data_extra_pool.empty()) { | |
2001 | return bucket.explicit_placement.data_pool; | |
2002 | } | |
2003 | return bucket.explicit_placement.data_extra_pool; | |
2004 | } | |
2005 | }; | |
2006 | WRITE_CLASS_ENCODER(rgw_obj) | |
2007 | ||
2008 | struct rgw_cache_entry_info { | |
2009 | string cache_locator; | |
2010 | uint64_t gen; | |
2011 | ||
2012 | rgw_cache_entry_info() : gen(0) {} | |
2013 | }; | |
2014 | ||
2015 | inline ostream& operator<<(ostream& out, const rgw_obj &o) { | |
2016 | return out << o.bucket.name << ":" << o.get_oid(); | |
2017 | } | |
2018 | ||
2019 | static inline void buf_to_hex(const unsigned char *buf, int len, char *str) | |
2020 | { | |
2021 | int i; | |
2022 | str[0] = '\0'; | |
2023 | for (i = 0; i < len; i++) { | |
2024 | sprintf(&str[i*2], "%02x", (int)buf[i]); | |
2025 | } | |
2026 | } | |
2027 | ||
2028 | static inline int hexdigit(char c) | |
2029 | { | |
2030 | if (c >= '0' && c <= '9') | |
2031 | return (c - '0'); | |
2032 | c = toupper(c); | |
2033 | if (c >= 'A' && c <= 'F') | |
2034 | return c - 'A' + 0xa; | |
2035 | return -EINVAL; | |
2036 | } | |
2037 | ||
2038 | static inline int hex_to_buf(const char *hex, char *buf, int len) | |
2039 | { | |
2040 | int i = 0; | |
2041 | const char *p = hex; | |
2042 | while (*p) { | |
2043 | if (i >= len) | |
2044 | return -EINVAL; | |
2045 | buf[i] = 0; | |
2046 | int d = hexdigit(*p); | |
2047 | if (d < 0) | |
2048 | return d; | |
2049 | buf[i] = d << 4; | |
2050 | p++; | |
2051 | if (!*p) | |
2052 | return -EINVAL; | |
2053 | d = hexdigit(*p); | |
2054 | if (d < 0) | |
2055 | return d; | |
2056 | buf[i] += d; | |
2057 | i++; | |
2058 | p++; | |
2059 | } | |
2060 | return i; | |
2061 | } | |
2062 | ||
2063 | static inline int rgw_str_to_bool(const char *s, int def_val) | |
2064 | { | |
2065 | if (!s) | |
2066 | return def_val; | |
2067 | ||
2068 | return (strcasecmp(s, "on") == 0 || | |
2069 | strcasecmp(s, "yes") == 0 || | |
2070 | strcasecmp(s, "1") == 0); | |
2071 | } | |
2072 | ||
2073 | static inline void append_rand_alpha(CephContext *cct, const string& src, string& dest, int len) | |
2074 | { | |
2075 | dest = src; | |
2076 | char buf[len + 1]; | |
2077 | gen_rand_alphanumeric(cct, buf, len); | |
2078 | dest.append("_"); | |
2079 | dest.append(buf); | |
2080 | } | |
2081 | ||
2082 | static inline const char *rgw_obj_category_name(RGWObjCategory category) | |
2083 | { | |
2084 | switch (category) { | |
2085 | case RGW_OBJ_CATEGORY_NONE: | |
2086 | return "rgw.none"; | |
2087 | case RGW_OBJ_CATEGORY_MAIN: | |
2088 | return "rgw.main"; | |
2089 | case RGW_OBJ_CATEGORY_SHADOW: | |
2090 | return "rgw.shadow"; | |
2091 | case RGW_OBJ_CATEGORY_MULTIMETA: | |
2092 | return "rgw.multimeta"; | |
2093 | } | |
2094 | ||
2095 | return "unknown"; | |
2096 | } | |
2097 | ||
2098 | static inline uint64_t rgw_rounded_kb(uint64_t bytes) | |
2099 | { | |
2100 | return (bytes + 1023) / 1024; | |
2101 | } | |
2102 | ||
2103 | static inline uint64_t rgw_rounded_objsize(uint64_t bytes) | |
2104 | { | |
2105 | return ((bytes + 4095) & ~4095); | |
2106 | } | |
2107 | ||
2108 | static inline uint64_t rgw_rounded_objsize_kb(uint64_t bytes) | |
2109 | { | |
2110 | return ((bytes + 4095) & ~4095) / 1024; | |
2111 | } | |
2112 | ||
2113 | extern string rgw_string_unquote(const string& s); | |
2114 | extern void parse_csv_string(const string& ival, vector<string>& ovals); | |
2115 | extern int parse_key_value(string& in_str, string& key, string& val); | |
2116 | extern int parse_key_value(string& in_str, const char *delim, string& key, string& val); | |
2117 | /** time parsing */ | |
2118 | extern int parse_time(const char *time_str, real_time *time); | |
2119 | extern bool parse_rfc2616(const char *s, struct tm *t); | |
2120 | extern bool parse_iso8601(const char *s, struct tm *t, uint32_t *pns = NULL, bool extended_format = true); | |
2121 | extern string rgw_trim_whitespace(const string& src); | |
2122 | extern boost::string_ref rgw_trim_whitespace(const boost::string_ref& src); | |
2123 | extern string rgw_trim_quotes(const string& val); | |
2124 | ||
2125 | extern void rgw_to_iso8601(const real_time& t, char *dest, int buf_size); | |
2126 | extern void rgw_to_iso8601(const real_time& t, string *dest); | |
2127 | ||
2128 | /** Check if the req_state's user has the necessary permissions | |
2129 | * to do the requested action */ | |
2130 | bool verify_user_permission(struct req_state * const s, | |
2131 | RGWAccessControlPolicy * const user_acl, | |
2132 | const int perm); | |
2133 | bool verify_user_permission(struct req_state * const s, | |
2134 | const int perm); | |
2135 | extern bool verify_bucket_permission(struct req_state * s, | |
2136 | RGWAccessControlPolicy * user_acl, | |
2137 | RGWAccessControlPolicy * bucket_acl, | |
2138 | int perm); | |
2139 | extern bool verify_bucket_permission(struct req_state *s, int perm); | |
2140 | extern bool verify_object_permission(struct req_state *s, | |
2141 | RGWAccessControlPolicy * user_acl, | |
2142 | RGWAccessControlPolicy * bucket_acl, | |
2143 | RGWAccessControlPolicy * object_acl, | |
2144 | int perm); | |
2145 | extern bool verify_object_permission(struct req_state *s, int perm); | |
2146 | /** Convert an input URL into a sane object name | |
2147 | * by converting %-escaped strings into characters, etc*/ | |
2148 | extern void rgw_uri_escape_char(char c, string& dst); | |
2149 | extern bool url_decode(const std::string& src_str, | |
2150 | std::string& dest_str, | |
2151 | bool in_query = false); | |
2152 | extern void url_encode(const std::string& src, | |
2153 | string& dst); | |
2154 | extern std::string url_encode(const std::string& src); | |
2155 | ||
2156 | /* destination should be CEPH_CRYPTO_HMACSHA1_DIGESTSIZE bytes long */ | |
2157 | extern void calc_hmac_sha1(const char *key, int key_len, | |
2158 | const char *msg, int msg_len, char *dest); | |
2159 | /* destination should be CEPH_CRYPTO_HMACSHA256_DIGESTSIZE bytes long */ | |
2160 | extern void calc_hmac_sha256(const char *key, int key_len, const char *msg, int msg_len, char *dest); | |
2161 | extern void calc_hash_sha256(const char *msg, int len, string& dest); | |
2162 | extern void calc_hash_sha256(const string& msg, string& dest); | |
2163 | ||
2164 | using ceph::crypto::SHA256; | |
2165 | extern SHA256* calc_hash_sha256_open_stream(); | |
2166 | extern void calc_hash_sha256_update_stream(SHA256 *hash, const char *msg, int len); | |
2167 | extern string calc_hash_sha256_close_stream(SHA256 **hash); | |
2168 | ||
2169 | extern int rgw_parse_op_type_list(const string& str, uint32_t *perm); | |
2170 | ||
2171 | int match(const string& pattern, const string& input, int flag); | |
2172 | #endif |