]> git.proxmox.com Git - ceph.git/blob - ceph/src/rgw/rgw_acl_types.h
bump version to 18.2.4-pve3
[ceph.git] / ceph / src / rgw / rgw_acl_types.h
1 // -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
2 // vim: ts=8 sw=2 smarttab ft=cpp
3
4 /*
5 * Ceph - scalable distributed file system
6 *
7 * Copyright (C) 2019 Red Hat, Inc.
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 /* N.B., this header defines fundamental serialized types. Do not
17 * introduce changes or include files which can only be compiled in
18 * radosgw or OSD contexts (e.g., rgw_sal.h, rgw_common.h)
19 */
20
21 #pragma once
22
23 #include <string>
24 #include <list>
25 #include <fmt/format.h>
26
27 #include "include/types.h"
28 #include "common/Formatter.h"
29
30 #define RGW_PERM_NONE 0x00
31 #define RGW_PERM_READ 0x01
32 #define RGW_PERM_WRITE 0x02
33 #define RGW_PERM_READ_ACP 0x04
34 #define RGW_PERM_WRITE_ACP 0x08
35 #define RGW_PERM_READ_OBJS 0x10
36 #define RGW_PERM_WRITE_OBJS 0x20
37 #define RGW_PERM_FULL_CONTROL ( RGW_PERM_READ | RGW_PERM_WRITE | \
38 RGW_PERM_READ_ACP | RGW_PERM_WRITE_ACP )
39 #define RGW_PERM_ALL_S3 RGW_PERM_FULL_CONTROL
40 #define RGW_PERM_INVALID 0xFF00
41
42 static constexpr char RGW_REFERER_WILDCARD[] = "*";
43
44 struct RGWAccessKey {
45 std::string id; // AccessKey
46 std::string key; // SecretKey
47 std::string subuser;
48
49 RGWAccessKey() {}
50 RGWAccessKey(std::string _id, std::string _key)
51 : id(std::move(_id)), key(std::move(_key)) {}
52
53 void encode(bufferlist& bl) const {
54 ENCODE_START(2, 2, bl);
55 encode(id, bl);
56 encode(key, bl);
57 encode(subuser, bl);
58 ENCODE_FINISH(bl);
59 }
60
61 void decode(bufferlist::const_iterator& bl) {
62 DECODE_START_LEGACY_COMPAT_LEN_32(2, 2, 2, bl);
63 decode(id, bl);
64 decode(key, bl);
65 decode(subuser, bl);
66 DECODE_FINISH(bl);
67 }
68 void dump(Formatter *f) const;
69 void dump_plain(Formatter *f) const;
70 void dump(Formatter *f, const std::string& user, bool swift) const;
71 static void generate_test_instances(std::list<RGWAccessKey*>& o);
72
73 void decode_json(JSONObj *obj);
74 void decode_json(JSONObj *obj, bool swift);
75 };
76 WRITE_CLASS_ENCODER(RGWAccessKey)
77
78 struct RGWSubUser {
79 std::string name;
80 uint32_t perm_mask;
81
82 RGWSubUser() : perm_mask(0) {}
83 void encode(bufferlist& bl) const {
84 ENCODE_START(2, 2, bl);
85 encode(name, bl);
86 encode(perm_mask, bl);
87 ENCODE_FINISH(bl);
88 }
89
90 void decode(bufferlist::const_iterator& bl) {
91 DECODE_START_LEGACY_COMPAT_LEN_32(2, 2, 2, bl);
92 decode(name, bl);
93 decode(perm_mask, bl);
94 DECODE_FINISH(bl);
95 }
96 void dump(Formatter *f) const;
97 void dump(Formatter *f, const std::string& user) const;
98 static void generate_test_instances(std::list<RGWSubUser*>& o);
99
100 void decode_json(JSONObj *obj);
101 };
102 WRITE_CLASS_ENCODER(RGWSubUser)
103
104 class RGWUserCaps
105 {
106 std::map<std::string, uint32_t> caps;
107
108 int get_cap(const std::string& cap, std::string& type, uint32_t *perm);
109 int add_cap(const std::string& cap);
110 int remove_cap(const std::string& cap);
111 public:
112 static int parse_cap_perm(const std::string& str, uint32_t *perm);
113 int add_from_string(const std::string& str);
114 int remove_from_string(const std::string& str);
115
116 void encode(bufferlist& bl) const {
117 ENCODE_START(1, 1, bl);
118 encode(caps, bl);
119 ENCODE_FINISH(bl);
120 }
121 void decode(bufferlist::const_iterator& bl) {
122 DECODE_START(1, bl);
123 decode(caps, bl);
124 DECODE_FINISH(bl);
125 }
126 int check_cap(const std::string& cap, uint32_t perm) const;
127 bool is_valid_cap_type(const std::string& tp);
128 void dump(Formatter *f) const;
129 void dump(Formatter *f, const char *name) const;
130
131 void decode_json(JSONObj *obj);
132 };
133 WRITE_CLASS_ENCODER(RGWUserCaps)
134
135 enum ACLGranteeTypeEnum {
136 /* numbers are encoded, should not change */
137 ACL_TYPE_CANON_USER = 0,
138 ACL_TYPE_EMAIL_USER = 1,
139 ACL_TYPE_GROUP = 2,
140 ACL_TYPE_UNKNOWN = 3,
141 ACL_TYPE_REFERER = 4,
142 };
143
144 enum ACLGroupTypeEnum {
145 /* numbers are encoded should not change */
146 ACL_GROUP_NONE = 0,
147 ACL_GROUP_ALL_USERS = 1,
148 ACL_GROUP_AUTHENTICATED_USERS = 2,
149 };
150
151 class ACLPermission
152 {
153 protected:
154 int flags;
155 public:
156 ACLPermission() : flags(0) {}
157 ~ACLPermission() {}
158 uint32_t get_permissions() const { return flags; }
159 void set_permissions(uint32_t perm) { flags = perm; }
160
161 void encode(bufferlist& bl) const {
162 ENCODE_START(2, 2, bl);
163 encode(flags, bl);
164 ENCODE_FINISH(bl);
165 }
166 void decode(bufferlist::const_iterator& bl) {
167 DECODE_START_LEGACY_COMPAT_LEN(2, 2, 2, bl);
168 decode(flags, bl);
169 DECODE_FINISH(bl);
170 }
171 void dump(Formatter *f) const;
172 static void generate_test_instances(std::list<ACLPermission*>& o);
173
174 friend bool operator==(const ACLPermission& lhs, const ACLPermission& rhs);
175 friend bool operator!=(const ACLPermission& lhs, const ACLPermission& rhs);
176 };
177 WRITE_CLASS_ENCODER(ACLPermission)
178
179 class ACLGranteeType
180 {
181 protected:
182 __u32 type;
183 public:
184 ACLGranteeType() : type(ACL_TYPE_UNKNOWN) {}
185 virtual ~ACLGranteeType() {}
186 // virtual const char *to_string() = 0;
187 ACLGranteeTypeEnum get_type() const { return (ACLGranteeTypeEnum)type; }
188 void set(ACLGranteeTypeEnum t) { type = t; }
189 // virtual void set(const char *s) = 0;
190 void encode(bufferlist& bl) const {
191 ENCODE_START(2, 2, bl);
192 encode(type, bl);
193 ENCODE_FINISH(bl);
194 }
195 void decode(bufferlist::const_iterator& bl) {
196 DECODE_START_LEGACY_COMPAT_LEN(2, 2, 2, bl);
197 decode(type, bl);
198 DECODE_FINISH(bl);
199 }
200 void dump(Formatter *f) const;
201 static void generate_test_instances(std::list<ACLGranteeType*>& o);
202
203 friend bool operator==(const ACLGranteeType& lhs, const ACLGranteeType& rhs);
204 friend bool operator!=(const ACLGranteeType& lhs, const ACLGranteeType& rhs);
205 };
206 WRITE_CLASS_ENCODER(ACLGranteeType)
207
208 class ACLGrantee
209 {
210 public:
211 ACLGrantee() {}
212 ~ACLGrantee() {}
213 };