summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorYehuda Sadeh <yehuda@inktank.com>2013-05-15 14:47:50 -0700
committerYehuda Sadeh <yehuda@inktank.com>2013-05-16 09:08:39 -0700
commitedb420c88d146f46a7f739f746d46219ca4014c7 (patch)
treec6b21dcfb9ad802c451bfee3983dc31eabfad7b8
parent2a441aa28abdffec5dd5f9bdbc219ac41fbc6d89 (diff)
downloadceph-edb420c88d146f46a7f739f746d46219ca4014c7.tar.gz
rgw: user has a tenant property
Signed-off-by: Yehuda Sadeh <yehuda@inktank.com>
-rw-r--r--src/Makefile.am3
-rw-r--r--src/rgw/rgw_acl.cc18
-rw-r--r--src/rgw/rgw_acl.h36
-rw-r--r--src/rgw/rgw_acl_s3.cc13
-rw-r--r--src/rgw/rgw_acl_s3.h6
-rw-r--r--src/rgw/rgw_acl_swift.cc35
-rw-r--r--src/rgw/rgw_acl_swift.h6
-rw-r--r--src/rgw/rgw_admin.cc9
-rw-r--r--src/rgw/rgw_basic_types.cc14
-rw-r--r--src/rgw/rgw_basic_types.h96
-rw-r--r--src/rgw/rgw_bucket.cc28
-rw-r--r--src/rgw/rgw_bucket.h22
-rw-r--r--src/rgw/rgw_common.h48
-rw-r--r--src/rgw/rgw_dencoder.cc6
-rw-r--r--src/rgw/rgw_json_enc.cc24
-rw-r--r--src/rgw/rgw_log.cc12
-rw-r--r--src/rgw/rgw_log.h20
-rw-r--r--src/rgw/rgw_op.cc2
-rw-r--r--src/rgw/rgw_rados.cc26
-rw-r--r--src/rgw/rgw_rados.h6
-rw-r--r--src/rgw/rgw_rest.cc4
-rw-r--r--src/rgw/rgw_rest.h2
-rw-r--r--src/rgw/rgw_rest_bucket.cc19
-rw-r--r--src/rgw/rgw_rest_usage.cc12
-rw-r--r--src/rgw/rgw_rest_user.cc65
-rw-r--r--src/rgw/rgw_swift.cc2
-rw-r--r--src/rgw/rgw_swift.h2
-rw-r--r--src/rgw/rgw_usage.cc4
-rw-r--r--src/rgw/rgw_usage.h4
-rw-r--r--src/rgw/rgw_user.cc76
-rw-r--r--src/rgw/rgw_user.h38
31 files changed, 432 insertions, 226 deletions
diff --git a/src/Makefile.am b/src/Makefile.am
index cb8dbb810c2..14dd2d5d75c 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -152,6 +152,7 @@ bin_PROGRAMS += monmaptool crushtool osdmaptool
rgw_dencoder_src = rgw/rgw_dencoder.cc \
rgw/rgw_acl.cc \
+ rgw/rgw_basic_types.cc \
rgw/rgw_common.cc \
rgw/rgw_json_enc.cc
@@ -384,6 +385,7 @@ librgw_a_SOURCES = \
rgw/rgw_rados.cc \
rgw/rgw_op.cc \
rgw/rgw_common.cc \
+ rgw/rgw_basic_types.cc \
rgw/rgw_cache.cc \
rgw/rgw_formats.cc \
rgw/rgw_log.cc \
@@ -1997,6 +1999,7 @@ noinst_HEADERS = \
rgw/rgw_xml.h\
rgw/rgw_cache.h\
rgw/rgw_common.h\
+ rgw/rgw_basic_types.h\
rgw/rgw_cors.h\
rgw/rgw_cors_s3.h\
rgw/rgw_cors_swift.h\
diff --git a/src/rgw/rgw_acl.cc b/src/rgw/rgw_acl.cc
index 3f99d72cd5b..64606f02acc 100644
--- a/src/rgw/rgw_acl.cc
+++ b/src/rgw/rgw_acl.cc
@@ -26,26 +26,26 @@ void RGWAccessControlList::_add_grant(ACLGrant *grant)
break;
default:
{
- string id;
+ rgw_user id;
if (!grant->get_id(id)) {
ldout(cct, 0) << "ERROR: grant->get_id() failed" << dendl;
}
- acl_user_map[id] |= perm.get_permissions();
+ acl_user_map[id.to_str()] |= perm.get_permissions();
}
}
}
void RGWAccessControlList::add_grant(ACLGrant *grant)
{
- string id;
+ rgw_user id;
grant->get_id(id); // not that this will return false for groups, but that's ok, we won't search groups
- grant_map.insert(pair<string, ACLGrant>(id, *grant));
+ grant_map.insert(pair<string, ACLGrant>(id.to_str(), *grant));
_add_grant(grant);
}
-int RGWAccessControlList::get_perm(string& id, int perm_mask) {
+int RGWAccessControlList::get_perm(rgw_user& id, int perm_mask) {
ldout(cct, 5) << "Searching permissions for uid=" << id << " mask=" << perm_mask << dendl;
- map<string, int>::iterator iter = acl_user_map.find(id);
+ map<string, int>::iterator iter = acl_user_map.find(id.to_str());
if (iter != acl_user_map.end()) {
ldout(cct, 5) << "Found permission: " << iter->second << dendl;
return iter->second & perm_mask;
@@ -65,7 +65,7 @@ int RGWAccessControlList::get_group_perm(ACLGroupTypeEnum group, int perm_mask)
return 0;
}
-int RGWAccessControlPolicy::get_perm(string& id, int perm_mask) {
+int RGWAccessControlPolicy::get_perm(rgw_user& id, int perm_mask) {
int perm = acl.get_perm(id, perm_mask);
if (id.compare(owner.get_id()) == 0) {
@@ -79,7 +79,7 @@ int RGWAccessControlPolicy::get_perm(string& id, int perm_mask) {
if ((perm & perm_mask) != perm_mask) {
perm |= acl.get_group_perm(ACL_GROUP_ALL_USERS, perm_mask);
- if (compare_group_name(id, ACL_GROUP_ALL_USERS) != 0) {
+ if (compare_group_name(id.id, ACL_GROUP_ALL_USERS) != 0) {
/* this is not the anonymous user */
perm |= acl.get_group_perm(ACL_GROUP_AUTHENTICATED_USERS, perm_mask);
}
@@ -90,7 +90,7 @@ int RGWAccessControlPolicy::get_perm(string& id, int perm_mask) {
return perm;
}
-bool RGWAccessControlPolicy::verify_permission(string& uid, int user_perm_mask, int perm)
+bool RGWAccessControlPolicy::verify_permission(rgw_user& uid, int user_perm_mask, int perm)
{
int test_perm = perm | RGW_PERM_READ_OBJS | RGW_PERM_WRITE_OBJS;
diff --git a/src/rgw/rgw_acl.h b/src/rgw/rgw_acl.h
index c06e9eb3c88..759e0e95a73 100644
--- a/src/rgw/rgw_acl.h
+++ b/src/rgw/rgw_acl.h
@@ -8,6 +8,8 @@
#include "common/debug.h"
+#include "rgw_basic_types.h"
+
using namespace std;
@@ -99,7 +101,7 @@ class ACLGrant
{
protected:
ACLGranteeType type;
- string id;
+ rgw_user id;
string email;
ACLPermission permission;
string name;
@@ -111,7 +113,7 @@ public:
/* there's an assumption here that email/uri/id encodings are
different and there can't be any overlap */
- bool get_id(string& _id) {
+ bool get_id(rgw_user& _id) {
switch(type.get_type()) {
case ACL_TYPE_EMAIL_USER:
_id = email;
@@ -163,7 +165,7 @@ public:
ACLGroupTypeEnum uri_to_group(string& uri);
- void set_canon(string& _id, string& _name, int perm) {
+ void set_canon(rgw_user& _id, string& _name, int perm) {
type.set(ACL_TYPE_CANON_USER);
id = _id;
name = _name;
@@ -195,7 +197,7 @@ public:
virtual ~RGWAccessControlList() {}
- int get_perm(string& id, int perm_mask);
+ int get_perm(rgw_user& id, int perm_mask);
int get_group_perm(ACLGroupTypeEnum group, int perm_mask);
void encode(bufferlist& bl) const {
ENCODE_START(3, 3, bl);
@@ -230,7 +232,7 @@ public:
multimap<string, ACLGrant>& get_grant_map() { return grant_map; }
- void create_default(string id, string name) {
+ void create_default(rgw_user& id, string name) {
acl_user_map.clear();
acl_group_map.clear();
@@ -244,30 +246,34 @@ WRITE_CLASS_ENCODER(RGWAccessControlList)
class ACLOwner
{
protected:
- string id;
+ rgw_user id;
string display_name;
public:
ACLOwner() {}
~ACLOwner() {}
void encode(bufferlist& bl) const {
- ENCODE_START(2, 2, bl);
- ::encode(id, bl);
+ ENCODE_START(3, 2, bl);
+ string s;
+ id.to_str(s);
+ ::encode(s, bl);
::encode(display_name, bl);
ENCODE_FINISH(bl);
}
void decode(bufferlist::iterator& bl) {
- DECODE_START_LEGACY_COMPAT_LEN(2, 2, 2, bl);
- ::decode(id, bl);
+ DECODE_START_LEGACY_COMPAT_LEN(3, 2, 2, bl);
+ string s;
+ ::decode(s, bl);
+ id.from_str(s);
::decode(display_name, bl);
DECODE_FINISH(bl);
}
void dump(Formatter *f) const;
static void generate_test_instances(list<ACLOwner*>& o);
- void set_id(const string& _id) { id = _id; }
+ void set_id(rgw_user& _id) { id = _id; }
void set_name(string& name) { display_name = name; }
- string& get_id() { return id; }
+ rgw_user& get_id() { return id; }
string& get_display_name() { return display_name; }
};
WRITE_CLASS_ENCODER(ACLOwner)
@@ -289,9 +295,9 @@ public:
acl.set_ctx(ctx);
}
- int get_perm(string& id, int perm_mask);
+ int get_perm(rgw_user& id, int perm_mask);
int get_group_perm(ACLGroupTypeEnum group, int perm_mask);
- bool verify_permission(string& uid, int user_perm_mask, int perm);
+ bool verify_permission(rgw_user& uid, int user_perm_mask, int perm);
void encode(bufferlist& bl) const {
ENCODE_START(2, 2, bl);
@@ -318,7 +324,7 @@ public:
return owner;
}
- void create_default(string& id, string& name) {
+ void create_default(rgw_user& id, string& name) {
acl.create_default(id, name);
owner.set_id(id);
owner.set_name(name);
diff --git a/src/rgw/rgw_acl_s3.cc b/src/rgw/rgw_acl_s3.cc
index 4f26dda7d20..b1b7c66c975 100644
--- a/src/rgw/rgw_acl_s3.cc
+++ b/src/rgw/rgw_acl_s3.cc
@@ -297,7 +297,8 @@ static int parse_grantee_str(RGWRados *store, string& grantee_str,
grant.set_canon(info.user_id, info.display_name, rgw_perm);
} else if (strcasecmp(id_type.c_str(), "id") == 0) {
- ret = rgw_get_user_info_by_uid(store, id_val, info);
+ rgw_user user(id_val);
+ ret = rgw_get_user_info_by_uid(store, user, info);
if (ret < 0)
return ret;
@@ -347,7 +348,7 @@ int RGWAccessControlList_S3::create_canned(ACLOwner& owner, ACLOwner& bucket_own
ACLGrant owner_grant;
- string bid = bucket_owner.get_id();
+ rgw_user bid = bucket_owner.get_id();
string bname = bucket_owner.get_display_name();
/* owner gets full control */
@@ -479,16 +480,18 @@ int RGWAccessControlPolicy_S3::rebuild(RGWRados *store, ACLOwner *owner, RGWAcce
ACLGranteeType& type = src_grant.get_type();
ACLGrant new_grant;
bool grant_ok = false;
- string uid;
+ rgw_user uid;
RGWUserInfo grant_user;
switch (type.get_type()) {
case ACL_TYPE_EMAIL_USER:
{
string email;
- if (!src_grant.get_id(email)) {
+ rgw_user u;
+ if (!src_grant.get_id(u)) {
ldout(cct, 0) << "ERROR: src_grant.get_id() failed" << dendl;
return -EINVAL;
}
+ email = u.id;
ldout(cct, 10) << "grant user email=" << email << dendl;
if (rgw_get_user_info_by_email(store, email, grant_user) < 0) {
ldout(cct, 10) << "grant user email not found or other error" << dendl;
@@ -512,7 +515,7 @@ int RGWAccessControlPolicy_S3::rebuild(RGWRados *store, ACLOwner *owner, RGWAcce
ACLPermission& perm = src_grant.get_permission();
new_grant.set_canon(uid, grant_user.display_name, perm.get_permissions());
grant_ok = true;
- string new_id;
+ rgw_user new_id;
new_grant.get_id(new_id);
ldout(cct, 10) << "new grant: " << new_id << ":" << grant_user.display_name << dendl;
}
diff --git a/src/rgw/rgw_acl_s3.h b/src/rgw/rgw_acl_s3.h
index 6c14d1df1ad..d7aeae6da0b 100644
--- a/src/rgw/rgw_acl_s3.h
+++ b/src/rgw/rgw_acl_s3.h
@@ -79,9 +79,11 @@ public:
bool xml_end(const char *el);
void to_xml(ostream& out) {
- if (id.empty())
+ string s;
+ id.to_str(s);
+ if (s.empty())
return;
- out << "<Owner>" << "<ID>" << id << "</ID>";
+ out << "<Owner>" << "<ID>" << s << "</ID>";
if (!display_name.empty())
out << "<DisplayName>" << display_name << "</DisplayName>";
out << "</Owner>";
diff --git a/src/rgw/rgw_acl_swift.cc b/src/rgw/rgw_acl_swift.cc
index b02ce90f538..9ac0b0a7941 100644
--- a/src/rgw/rgw_acl_swift.cc
+++ b/src/rgw/rgw_acl_swift.cc
@@ -1,7 +1,7 @@
#include <string.h>
-#include <vector>
+#include <list>
#include "rgw_common.h"
#include "rgw_user.h"
@@ -16,7 +16,7 @@ using namespace std;
#define SWIFT_GROUP_ALL_USERS ".r:*"
-static int parse_list(string& uid_list, vector<string>& uids)
+static int parse_list(string& uid_list, list<string>& uids)
{
char *s = strdup(uid_list.c_str());
if (!s)
@@ -54,9 +54,9 @@ static bool uid_is_public(string& uid)
sub.compare(".referrer") == 0;
}
-void RGWAccessControlPolicy_SWIFT::add_grants(RGWRados *store, vector<string>& uids, int perm)
+void RGWAccessControlPolicy_SWIFT::add_grants(RGWRados *store, list<string>& uids, int perm)
{
- vector<string>::iterator iter;
+ list<string>::iterator iter;
for (iter = uids.begin(); iter != uids.end(); ++iter ) {
ACLGrant grant;
RGWUserInfo grant_user;
@@ -64,24 +64,27 @@ void RGWAccessControlPolicy_SWIFT::add_grants(RGWRados *store, vector<string>& u
if (uid_is_public(uid)) {
grant.set_group(ACL_GROUP_ALL_USERS, perm);
acl.add_grant(&grant);
- } else if (rgw_get_user_info_by_uid(store, uid, grant_user) < 0) {
- ldout(cct, 10) << "grant user does not exist:" << uid << dendl;
- /* skipping silently */
- } else {
- grant.set_canon(uid, grant_user.display_name, perm);
- acl.add_grant(&grant);
+ } else {
+ rgw_user user(uid);
+ if (rgw_get_user_info_by_uid(store, user, grant_user) < 0) {
+ ldout(cct, 10) << "grant user does not exist:" << uid << dendl;
+ /* skipping silently */
+ } else {
+ grant.set_canon(user, grant_user.display_name, perm);
+ acl.add_grant(&grant);
+ }
}
}
}
-bool RGWAccessControlPolicy_SWIFT::create(RGWRados *store, string& id, string& name, string& read_list, string& write_list)
+bool RGWAccessControlPolicy_SWIFT::create(RGWRados *store, rgw_user& id, string& name, string& read_list, string& write_list)
{
acl.create_default(id, name);
owner.set_id(id);
owner.set_name(name);
if (read_list.size()) {
- vector<string> uids;
+ list<string> uids;
int r = parse_list(read_list, uids);
if (r < 0) {
ldout(cct, 0) << "ERROR: parse_list returned r=" << r << dendl;
@@ -91,7 +94,7 @@ bool RGWAccessControlPolicy_SWIFT::create(RGWRados *store, string& id, string& n
add_grants(store, uids, SWIFT_PERM_READ);
}
if (write_list.size()) {
- vector<string> uids;
+ list<string> uids;
int r = parse_list(write_list, uids);
if (r < 0) {
ldout(cct, 0) << "ERROR: parse_list returned r=" << r << dendl;
@@ -111,7 +114,7 @@ void RGWAccessControlPolicy_SWIFT::to_str(string& read, string& write)
for (iter = m.begin(); iter != m.end(); ++iter) {
ACLGrant& grant = iter->second;
int perm = grant.get_permission().get_permissions();
- string id;
+ rgw_user id;
if (!grant.get_id(id)) {
if (grant.get_group() != ACL_GROUP_ALL_USERS)
continue;
@@ -120,11 +123,11 @@ void RGWAccessControlPolicy_SWIFT::to_str(string& read, string& write)
if (perm & SWIFT_PERM_READ) {
if (!read.empty())
read.append(", ");
- read.append(id);
+ read.append(id.to_str());
} else if (perm & SWIFT_PERM_WRITE) {
if (!write.empty())
write.append(", ");
- write.append(id);
+ write.append(id.to_str());
}
}
}
diff --git a/src/rgw/rgw_acl_swift.h b/src/rgw/rgw_acl_swift.h
index be64f58021f..147e26c31fd 100644
--- a/src/rgw/rgw_acl_swift.h
+++ b/src/rgw/rgw_acl_swift.h
@@ -4,7 +4,7 @@
#include <map>
#include <string>
#include <iostream>
-#include <vector>
+#include <list>
#include <include/types.h>
#include "rgw_acl.h"
@@ -17,8 +17,8 @@ public:
RGWAccessControlPolicy_SWIFT(CephContext *_cct) : RGWAccessControlPolicy(_cct) {}
~RGWAccessControlPolicy_SWIFT() {}
- void add_grants(RGWRados *store, vector<string>& uids, int perm);
- bool create(RGWRados *store, string& id, string& name, string& read_list, string& write_list);
+ void add_grants(RGWRados *store, list<string>& uids, int perm);
+ bool create(RGWRados *store, rgw_user& id, string& name, string& read_list, string& write_list);
void to_str(string& read, string& write);
};
diff --git a/src/rgw/rgw_admin.cc b/src/rgw/rgw_admin.cc
index fff32ca435d..71acb8a7f6f 100644
--- a/src/rgw/rgw_admin.cc
+++ b/src/rgw/rgw_admin.cc
@@ -355,7 +355,7 @@ int bucket_stats(rgw_bucket& bucket, Formatter *formatter)
formatter->dump_string("id", bucket.bucket_id);
formatter->dump_string("marker", bucket.marker);
- formatter->dump_string("owner", bucket_info.owner);
+ formatter->dump_string("owner", bucket_info.owner.to_str());
dump_bucket_usage(stats, formatter);
formatter->close_section();
@@ -454,7 +454,8 @@ int main(int argc, char **argv)
global_init(NULL, args, CEPH_ENTITY_TYPE_CLIENT, CODE_ENVIRONMENT_UTILITY, 0);
common_init_finish(g_ceph_context);
- std::string user_id, access_key, secret_key, user_email, display_name;
+ rgw_user user_id;
+ std::string access_key, secret_key, user_email, display_name;
std::string bucket_name, pool_name, object;
std::string date, subuser, access, format;
std::string start_date, end_date;
@@ -499,7 +500,7 @@ int main(int argc, char **argv)
usage();
return 0;
} else if (ceph_argparse_witharg(args, i, &val, "-i", "--uid", (char*)NULL)) {
- user_id = val;
+ user_id.from_str(val);
} else if (ceph_argparse_witharg(args, i, &val, "--access-key", (char*)NULL)) {
access_key = val;
} else if (ceph_argparse_witharg(args, i, &val, "--subuser", (char*)NULL)) {
@@ -946,7 +947,7 @@ int main(int argc, char **argv)
return -r;
}
formatter->dump_string("bucket_id", entry.bucket_id);
- formatter->dump_string("bucket_owner", entry.bucket_owner);
+ formatter->dump_string("bucket_owner", entry.bucket_owner.to_str());
formatter->dump_string("bucket", entry.bucket);
uint64_t agg_time = 0;
diff --git a/src/rgw/rgw_basic_types.cc b/src/rgw/rgw_basic_types.cc
new file mode 100644
index 00000000000..60d731be48d
--- /dev/null
+++ b/src/rgw/rgw_basic_types.cc
@@ -0,0 +1,14 @@
+#include "rgw_basic_types.h"
+#include "common/ceph_json.h"
+
+void decode_json_obj(rgw_user& val, JSONObj *obj)
+{
+ string s = obj->get_data();
+ val.from_str(s);
+}
+
+void encode_json(const char *name, rgw_user& val, Formatter *f)
+{
+ string s = val.to_str();
+ f->dump_string(name, s);
+}
diff --git a/src/rgw/rgw_basic_types.h b/src/rgw/rgw_basic_types.h
new file mode 100644
index 00000000000..c9886d66665
--- /dev/null
+++ b/src/rgw/rgw_basic_types.h
@@ -0,0 +1,96 @@
+#ifndef CEPH_RGW_BASIC_TYPES_H
+#define CEPH_RGW_BASIC_TYPES_H
+
+#include <string>
+
+#include "include/types.h"
+
+struct rgw_user {
+ std::string tenant;
+ std::string id;
+
+ rgw_user() {}
+ rgw_user(const std::string& s) {
+ from_str(s);
+ }
+
+ void encode(bufferlist& bl) const {
+ ENCODE_START(1, 1, bl);
+ ::encode(tenant, bl);
+ ::encode(id, bl);
+ ENCODE_FINISH(bl);
+ }
+ void decode(bufferlist::iterator& bl) {
+ DECODE_START(1, bl);
+ ::decode(tenant, bl);
+ ::decode(id, bl);
+ DECODE_FINISH(bl);
+ }
+
+ void to_str(std::string& str) const {
+ if (!tenant.empty()) {
+ str = tenant + ':' + id;
+ } else {
+ str = id;
+ }
+ }
+
+ void clear() {
+ tenant.clear();
+ id.clear();
+ }
+
+ bool empty() {
+ return id.empty();
+ }
+
+ string to_str() const {
+ string s;
+ to_str(s);
+ return s;
+ }
+
+ void from_str(const std::string& str) {
+ ssize_t pos = str.find(':');
+ if (pos >= 0) {
+ tenant = str.substr(0, pos);
+ id = str.substr(pos + 1);
+ } else {
+ tenant.clear();
+ id = str;
+ }
+ }
+
+ rgw_user& operator=(const string& str) {
+ from_str(str);
+ return *this;
+ }
+
+ int compare(const rgw_user& u) const {
+ int r = tenant.compare(u.tenant);
+ if (r != 0)
+ return r;
+
+ return id.compare(u.id);
+ }
+ int compare(const string& str) const {
+ rgw_user u(str);
+ return compare(u);
+ }
+};
+WRITE_CLASS_ENCODER(rgw_user)
+
+
+class JSONObj;
+
+void decode_json_obj(rgw_user& val, JSONObj *obj);
+void encode_json(const char *name, rgw_user& val, Formatter *f);
+
+inline ostream& operator<<(ostream& out, const rgw_user &u) {
+ string s;
+ u.to_str(s);
+ return out << s;
+}
+
+
+#endif
diff --git a/src/rgw/rgw_bucket.cc b/src/rgw/rgw_bucket.cc
index 2f05264778e..cc0ad0d2eb1 100644
--- a/src/rgw/rgw_bucket.cc
+++ b/src/rgw/rgw_bucket.cc
@@ -23,9 +23,10 @@
using namespace std;
// define as static when RGWBucket implementation compete
-void rgw_get_buckets_obj(string& user_id, string& buckets_obj_id)
+void rgw_get_buckets_obj(const rgw_user& user_id, string& buckets_obj_id)
{
- buckets_obj_id = user_id;
+ string s = user_id.to_str();
+ buckets_obj_id = s;
buckets_obj_id += RGW_BUCKETS_OBJ_PREFIX;
}
@@ -33,7 +34,7 @@ void rgw_get_buckets_obj(string& user_id, string& buckets_obj_id)
* Get all the buckets owned by a user and fill up an RGWUserBuckets with them.
* Returns: 0 on success, -ERR# on failure.
*/
-int rgw_read_user_buckets(RGWRados *store, string user_id, RGWUserBuckets& buckets,
+int rgw_read_user_buckets(RGWRados *store, const rgw_user& user_id, RGWUserBuckets& buckets,
const string& marker, uint64_t max, bool need_stats)
{
int ret;
@@ -75,19 +76,21 @@ int rgw_read_user_buckets(RGWRados *store, string user_id, RGWUserBuckets& bucke
* This completely overwrites any previously-stored list, so be careful!
* Returns 0 on success, -ERR# otherwise.
*/
-int rgw_write_buckets_attr(RGWRados *store, string user_id, RGWUserBuckets& buckets)
+int rgw_write_buckets_attr(RGWRados *store, rgw_user& user_id, RGWUserBuckets& buckets)
{
bufferlist bl;
buckets.encode(bl);
- rgw_obj obj(store->zone.user_uid_pool, user_id);
+ string oid = user_id.to_str();
+
+ rgw_obj obj(store->zone.user_uid_pool, oid);
int ret = store->set_attr(NULL, obj, RGW_ATTR_BUCKETS, bl);
return ret;
}
-int rgw_add_bucket(RGWRados *store, string user_id, rgw_bucket& bucket)
+int rgw_add_bucket(RGWRados *store, const rgw_user& user_id, rgw_bucket& bucket)
{
int ret;
string& bucket_name = bucket.name;
@@ -113,7 +116,7 @@ int rgw_add_bucket(RGWRados *store, string user_id, rgw_bucket& bucket)
return ret;
}
-int rgw_remove_user_bucket_info(RGWRados *store, string user_id, rgw_bucket& bucket)
+int rgw_remove_user_bucket_info(RGWRados *store, rgw_user& user_id, rgw_bucket& bucket)
{
int ret;
@@ -132,7 +135,7 @@ int rgw_remove_user_bucket_info(RGWRados *store, string user_id, rgw_bucket& buc
return ret;
}
-int RGWBucket::create_bucket(string bucket_str, string& user_id, string& display_name)
+int RGWBucket::create_bucket(string bucket_str, rgw_user& user_id, string& display_name)
{
RGWAccessControlPolicy policy, old_policy;
map<string, bufferlist> attrs;
@@ -188,7 +191,7 @@ static void dump_mulipart_index_results(list<std::string>& objs_to_unlink,
f->close_section();
}
-void check_bad_user_bucket_mapping(RGWRados *store, const string& user_id, bool fix)
+void check_bad_user_bucket_mapping(RGWRados *store, const rgw_user& user_id, bool fix)
{
RGWUserBuckets user_buckets;
bool done;
@@ -383,7 +386,6 @@ int RGWBucket::link(RGWBucketAdminOpState& op_state, std::string *err_msg)
std::string display_name = op_state.get_user_display_name();
rgw_bucket bucket = op_state.get_bucket();
- string uid_str(user_id);
bufferlist aclbl;
rgw_obj obj(bucket, no_oid);
@@ -402,7 +404,7 @@ int RGWBucket::link(RGWBucketAdminOpState& op_state, std::string *err_msg)
r = rgw_remove_user_bucket_info(store, owner.get_id(), bucket);
if (r < 0) {
- set_err_msg(err_msg, "could not unlink policy from user " + owner.get_id());
+ set_err_msg(err_msg, "could not unlink policy from user " + owner.get_id().to_str());
return r;
}
@@ -432,7 +434,7 @@ int RGWBucket::link(RGWBucketAdminOpState& op_state, std::string *err_msg)
return r;
} else {
// the bucket seems not to exist, so we should probably create it...
- r = create_bucket(bucket_name.c_str(), uid_str, display_name);
+ r = create_bucket(bucket_name.c_str(), user_id, display_name);
if (r < 0) {
set_err_msg(err_msg, "error linking bucket to user r=" + cpp_strerror(-r));
}
@@ -851,7 +853,7 @@ static int bucket_stats(RGWRados *store, std::string& bucket_name, Formatter *f
formatter->dump_string("id", bucket.bucket_id);
formatter->dump_string("marker", bucket.marker);
- formatter->dump_string("owner", bucket_info.owner);
+ formatter->dump_string("owner", bucket_info.owner.to_str());
dump_bucket_usage(stats, formatter);
formatter->close_section();
diff --git a/src/rgw/rgw_bucket.h b/src/rgw/rgw_bucket.h
index e2f4d5eee40..872c404c8de 100644
--- a/src/rgw/rgw_bucket.h
+++ b/src/rgw/rgw_bucket.h
@@ -18,7 +18,7 @@
using namespace std;
// define as static when RGWBucket implementation compete
-extern void rgw_get_buckets_obj(string& user_id, string& buckets_obj_id);
+extern void rgw_get_buckets_obj(const rgw_user& user_id, string& buckets_obj_id);
/**
@@ -81,7 +81,7 @@ WRITE_CLASS_ENCODER(RGWUserBuckets)
* Get all the buckets owned by a user and fill up an RGWUserBuckets with them.
* Returns: 0 on success, -ERR# on failure.
*/
-extern int rgw_read_user_buckets(RGWRados *store, string user_id, RGWUserBuckets& buckets,
+extern int rgw_read_user_buckets(RGWRados *store, const rgw_user& user_id, RGWUserBuckets& buckets,
const string& marker, uint64_t max, bool need_stats);
/**
@@ -89,18 +89,18 @@ extern int rgw_read_user_buckets(RGWRados *store, string user_id, RGWUserBuckets
* This completely overwrites any previously-stored list, so be careful!
* Returns 0 on success, -ERR# otherwise.
*/
-extern int rgw_write_buckets_attr(RGWRados *store, string user_id, RGWUserBuckets& buckets);
+extern int rgw_write_buckets_attr(RGWRados *store, rgw_user& user_id, RGWUserBuckets& buckets);
-extern int rgw_add_bucket(RGWRados *store, string user_id, rgw_bucket& bucket);
-extern int rgw_remove_user_bucket_info(RGWRados *store, string user_id, rgw_bucket& bucket);
+extern int rgw_add_bucket(RGWRados *store, const rgw_user& user_id, rgw_bucket& bucket);
+extern int rgw_remove_user_bucket_info(RGWRados *store, rgw_user& user_id, rgw_bucket& bucket);
extern int rgw_remove_object(RGWRados *store, rgw_bucket& bucket, std::string& object);
extern int rgw_remove_bucket(RGWRados *store, rgw_bucket& bucket, bool delete_children);
-extern void check_bad_user_bucket_mapping(RGWRados *store, const string& user_id, bool fix);
+extern void check_bad_user_bucket_mapping(RGWRados *store, const rgw_user& user_id, bool fix);
struct RGWBucketAdminOpState {
- std::string uid;
+ rgw_user uid;
std::string display_name;
std::string bucket_name;
std::string bucket_id;
@@ -120,7 +120,7 @@ struct RGWBucketAdminOpState {
void set_fix_index(bool value) { fix_index = value; }
void set_delete_children(bool value) { delete_child_objects = value; }
- void set_user_id(std::string& user_id) {
+ void set_user_id(rgw_user& user_id) {
if (!user_id.empty())
uid = user_id;
}
@@ -131,7 +131,7 @@ struct RGWBucketAdminOpState {
object_name = object_str;
}
- std::string& get_user_id() { return uid; };
+ rgw_user& get_user_id() { return uid; };
std::string& get_user_display_name() { return display_name; };
std::string& get_bucket_name() { return bucket_name; };
std::string& get_object_name() { return object_name; };
@@ -165,7 +165,7 @@ class RGWBucket
RGWRados *store;
RGWAccessHandle handle;
- std::string user_id;
+ rgw_user user_id;
std::string bucket_name;
bool failure;
@@ -176,7 +176,7 @@ public:
RGWBucket() : store(NULL), handle(NULL), failure(false) {}
int init(RGWRados *storage, RGWBucketAdminOpState& op_state);
- int create_bucket(string bucket_str, string& user_id, string& display_name);
+ int create_bucket(string bucket_str, rgw_user& user_id, string& display_name);
int check_bad_index_multipart(RGWBucketAdminOpState& op_state,
list<std::string>& objs_to_unlink, std::string *err_msg = NULL);
diff --git a/src/rgw/rgw_common.h b/src/rgw/rgw_common.h
index 9b761810286..db38e2c9622 100644
--- a/src/rgw/rgw_common.h
+++ b/src/rgw/rgw_common.h
@@ -29,6 +29,7 @@
#include "include/utime.h"
#include "rgw_acl.h"
#include "rgw_cors.h"
+#include "rgw_basic_types.h"
using namespace std;
@@ -379,7 +380,7 @@ void encode_json(const char *name, const RGWUserCaps& val, Formatter *f);
struct RGWUserInfo
{
uint64_t auid;
- string user_id;
+ rgw_user user_id;
string display_name;
string user_email;
map<string, RGWAccessKey> access_keys;
@@ -393,7 +394,7 @@ struct RGWUserInfo
RGWUserInfo() : auid(0), suspended(0), max_buckets(RGW_DEFAULT_MAX_BUCKETS), op_mask(RGW_OP_TYPE_ALL) {}
void encode(bufferlist& bl) const {
- ENCODE_START(12, 9, bl);
+ ENCODE_START(13, 9, bl);
::encode(auid, bl);
string access_key;
string secret_key;
@@ -417,7 +418,7 @@ struct RGWUserInfo
}
::encode(swift_name, bl);
::encode(swift_key, bl);
- ::encode(user_id, bl);
+ ::encode(user_id.id, bl);
::encode(access_keys, bl);
::encode(subusers, bl);
::encode(suspended, bl);
@@ -425,10 +426,11 @@ struct RGWUserInfo
::encode(max_buckets, bl);
::encode(caps, bl);
::encode(op_mask, bl);
+ ::encode(user_id, bl);
ENCODE_FINISH(bl);
}
void decode(bufferlist::iterator& bl) {
- DECODE_START_LEGACY_COMPAT_LEN_32(11, 9, 9, bl);
+ DECODE_START_LEGACY_COMPAT_LEN_32(13, 9, 9, bl);
if (struct_v >= 2) ::decode(auid, bl);
else auid = CEPH_AUTH_UID_DEFAULT;
string access_key;
@@ -447,10 +449,13 @@ struct RGWUserInfo
string swift_key;
if (struct_v >= 3) ::decode(swift_name, bl);
if (struct_v >= 4) ::decode(swift_key, bl);
+ if (struct_v < 13) {
+ user_id.tenant.clear();
+ }
if (struct_v >= 5)
- ::decode(user_id, bl);
+ ::decode(user_id.id, bl);
else
- user_id = access_key;
+ user_id.id = access_key;
if (struct_v >= 6) {
::decode(access_keys, bl);
::decode(subusers, bl);
@@ -475,21 +480,15 @@ struct RGWUserInfo
} else {
op_mask = RGW_OP_TYPE_ALL;
}
+ if (struct_v >= 13) {
+ ::decode(user_id, bl);
+ }
DECODE_FINISH(bl);
}
void dump(Formatter *f) const;
static void generate_test_instances(list<RGWUserInfo*>& o);
void decode_json(JSONObj *obj);
-
- void clear() {
- user_id.clear();
- display_name.clear();
- user_email.clear();
- auid = CEPH_AUTH_UID_DEFAULT;
- access_keys.clear();
- suspended = 0;
- }
};
WRITE_CLASS_ENCODER(RGWUserInfo)
@@ -560,23 +559,28 @@ enum RGWBucketFlags {
struct RGWBucketInfo
{
rgw_bucket bucket;
- string owner;
+ rgw_user owner;
uint32_t flags;
void encode(bufferlist& bl) const {
- ENCODE_START(4, 4, bl);
+ ENCODE_START(5, 4, bl);
::encode(bucket, bl);
- ::encode(owner, bl);
+ ::encode(owner.id, bl);
::encode(flags, bl);
ENCODE_FINISH(bl);
}
void decode(bufferlist::iterator& bl) {
- DECODE_START_LEGACY_COMPAT_LEN_32(4, 4, 4, bl);
+ DECODE_START_LEGACY_COMPAT_LEN_32(5, 4, 4, bl);
::decode(bucket, bl);
- if (struct_v >= 2)
- ::decode(owner, bl);
+ if (struct_v >= 2) {
+ string s;
+ ::decode(s, bl);
+ owner.from_str(s);
+ }
if (struct_v >= 3)
::decode(flags, bl);
+ if (struct_v >= 5)
+ ::decode(owner, bl);
DECODE_FINISH(bl);
}
void dump(Formatter *f) const;
@@ -671,7 +675,7 @@ struct req_state {
/** Store basic data on an object */
struct RGWObjEnt {
std::string name;
- std::string owner;
+ rgw_user owner;
std::string owner_display_name;
uint64_t size;
time_t mtime;
diff --git a/src/rgw/rgw_dencoder.cc b/src/rgw/rgw_dencoder.cc
index 1f4e3522788..3626c9a84e1 100644
--- a/src/rgw/rgw_dencoder.cc
+++ b/src/rgw/rgw_dencoder.cc
@@ -107,8 +107,8 @@ ACLGroupTypeEnum ACLGrant_S3::uri_to_group(string& uri)
void ACLGrant::generate_test_instances(list<ACLGrant*>& o)
{
- string id, name, email;
- id = "rgw";
+ rgw_user id("rgw");
+ string name, email;
name = "Mr. RGW";
email = "r@gw";
@@ -164,7 +164,7 @@ void RGWAccessControlPolicy::generate_test_instances(list<RGWAccessControlPolicy
p->acl = *l;
string name = "radosgw";
- string id = "rgw";
+ rgw_user id("rgw");
p->owner.set_name(name);
p->owner.set_id(id);
diff --git a/src/rgw/rgw_json_enc.cc b/src/rgw/rgw_json_enc.cc
index e26299f24ad..cd66f2d0dab 100644
--- a/src/rgw/rgw_json_enc.cc
+++ b/src/rgw/rgw_json_enc.cc
@@ -39,8 +39,8 @@ void RGWObjManifest::dump(Formatter *f) const
void rgw_log_entry::dump(Formatter *f) const
{
- f->dump_string("object_owner", object_owner);
- f->dump_string("bucket_owner", bucket_owner);
+ f->dump_string("object_owner", object_owner.to_str());
+ f->dump_string("bucket_owner", bucket_owner.to_str());
f->dump_string("bucket", bucket);
f->dump_stream("time") << time;
f->dump_string("remote_addr", remote_addr);
@@ -85,7 +85,7 @@ void ACLGrant::dump(Formatter *f) const
type.dump(f);
f->close_section();
- f->dump_string("id", id);
+ f->dump_string("id", id.to_str());
f->dump_string("email", email);
f->open_object_section("permission");
@@ -133,7 +133,7 @@ void RGWAccessControlList::dump(Formatter *f) const
void ACLOwner::dump(Formatter *f) const
{
- encode_json("id", id, f);
+ encode_json("id", id.to_str(), f);
encode_json("display_name", display_name, f);
}
@@ -326,25 +326,25 @@ void RGWSubUser::decode_json(JSONObj *obj)
static void user_info_dump_subuser(const char *name, const RGWSubUser& subuser, Formatter *f, void *parent)
{
RGWUserInfo *info = static_cast<RGWUserInfo *>(parent);
- subuser.dump(f, info->user_id);
+ subuser.dump(f, info->user_id.to_str());
}
static void user_info_dump_key(const char *name, const RGWAccessKey& key, Formatter *f, void *parent)
{
RGWUserInfo *info = static_cast<RGWUserInfo *>(parent);
- key.dump(f, info->user_id, false);
+ key.dump(f, info->user_id.to_str(), false);
}
static void user_info_dump_swift_key(const char *name, const RGWAccessKey& key, Formatter *f, void *parent)
{
RGWUserInfo *info = static_cast<RGWUserInfo *>(parent);
- key.dump(f, info->user_id, true);
+ key.dump(f, info->user_id.to_str(), true);
}
void RGWUserInfo::dump(Formatter *f) const
{
- encode_json("user_id", user_id, f);
+ encode_json("user_id", user_id.to_str(), f);
encode_json("display_name", display_name, f);
encode_json("email", user_email, f);
encode_json("suspended", (int)suspended, f);
@@ -387,7 +387,11 @@ static void decode_subusers(map<string, RGWSubUser>& m, JSONObj *o)
void RGWUserInfo::decode_json(JSONObj *obj)
{
- JSONDecoder::decode_json("user_id", user_id, obj, true);
+ string uid;
+
+ JSONDecoder::decode_json("user_id", uid, obj, true);
+ user_id.from_str(uid);
+
JSONDecoder::decode_json("display_name", display_name, obj);
JSONDecoder::decode_json("email", user_email, obj);
bool susp;
@@ -418,7 +422,7 @@ void rgw_bucket::dump(Formatter *f) const
void RGWBucketInfo::dump(Formatter *f) const
{
encode_json("bucket", bucket, f);
- encode_json("owner", owner, f);
+ encode_json("owner", owner.to_str(), f);
encode_json("flags", flags, f);
}
diff --git a/src/rgw/rgw_log.cc b/src/rgw/rgw_log.cc
index 09fdacf4f2f..053f0fe504e 100644
--- a/src/rgw/rgw_log.cc
+++ b/src/rgw/rgw_log.cc
@@ -169,14 +169,15 @@ static void log_usage(struct req_state *s, const string& op_name)
if (!usage_logger)
return;
- string user;
+ rgw_user user;
if (s->bucket_name)
user = s->bucket_owner.get_id();
else
user = s->user.user_id;
- rgw_usage_log_entry entry(user, s->bucket.name);
+ string id = user.to_str();
+ rgw_usage_log_entry entry(id, s->bucket.name);
uint64_t bytes_sent = s->cio->get_bytes_sent();
uint64_t bytes_received = s->cio->get_bytes_received();
@@ -201,8 +202,9 @@ void rgw_format_ops_log_entry(struct rgw_log_entry& entry, Formatter *formatter)
entry.time.gmtime(formatter->dump_stream("time")); // UTC
entry.time.localtime(formatter->dump_stream("time_local"));
formatter->dump_string("remote_addr", entry.remote_addr);
- if (entry.object_owner.length())
- formatter->dump_string("object_owner", entry.object_owner);
+ string obj_owner = entry.object_owner.to_str();
+ if (obj_owner.length())
+ formatter->dump_string("object_owner", obj_owner);
formatter->dump_string("user", entry.user);
formatter->dump_string("operation", entry.op);
formatter->dump_string("uri", entry.uri);
@@ -301,7 +303,7 @@ int rgw_log_op(RGWRados *store, struct req_state *s, const string& op_name, OpsL
set_param_str(s, "REQUEST_URI", entry.uri);
set_param_str(s, "REQUEST_METHOD", entry.op);
- entry.user = s->user.user_id;
+ entry.user = s->user.user_id.to_str();
if (s->object_acl)
entry.object_owner = s->object_acl->get_owner().get_id();
entry.bucket_owner = s->bucket_owner.get_id();
diff --git a/src/rgw/rgw_log.h b/src/rgw/rgw_log.h
index 823f0b1767f..f8d39cab952 100644
--- a/src/rgw/rgw_log.h
+++ b/src/rgw/rgw_log.h
@@ -9,8 +9,8 @@
class RGWRados;
struct rgw_log_entry {
- string object_owner;
- string bucket_owner;
+ rgw_user object_owner;
+ rgw_user bucket_owner;
string bucket;
utime_t time;
string remote_addr;
@@ -29,9 +29,9 @@ struct rgw_log_entry {
string bucket_id;
void encode(bufferlist &bl) const {
- ENCODE_START(6, 5, bl);
- ::encode(object_owner, bl);
- ::encode(bucket_owner, bl);
+ ENCODE_START(7, 5, bl);
+ ::encode(object_owner.id, bl);
+ ::encode(bucket_owner.id, bl);
::encode(bucket, bl);
::encode(time, bl);
::encode(remote_addr, bl);
@@ -48,11 +48,13 @@ struct rgw_log_entry {
::encode(referrer, bl);
::encode(bytes_received, bl);
::encode(bucket_id, bl);
+ ::encode(object_owner, bl);
+ ::encode(bucket_owner, bl);
ENCODE_FINISH(bl);
}
void decode(bufferlist::iterator &p) {
- DECODE_START_LEGACY_COMPAT_LEN(6, 5, 5, p);
- ::decode(object_owner, p);
+ DECODE_START_LEGACY_COMPAT_LEN(7, 5, 5, p);
+ ::decode(object_owner.id, p);
if (struct_v > 3)
::decode(bucket_owner, p);
::decode(bucket, p);
@@ -86,6 +88,10 @@ struct rgw_log_entry {
}
} else
bucket_id = "";
+ if (struct_v >= 7) {
+ ::decode(object_owner, p);
+ ::decode(bucket_owner, p);
+ }
DECODE_FINISH(p);
}
void dump(Formatter *f) const;
diff --git a/src/rgw/rgw_op.cc b/src/rgw/rgw_op.cc
index 0ba0dc3fb83..a482187cac7 100644
--- a/src/rgw/rgw_op.cc
+++ b/src/rgw/rgw_op.cc
@@ -266,7 +266,7 @@ static int read_policy(RGWRados *store, struct req_state *s, RGWBucketInfo& buck
ret = get_policy_from_attr(s->cct, store, s->obj_ctx, &bucket_policy, no_obj);
if (ret < 0)
return ret;
- string& owner = bucket_policy.get_owner().get_id();
+ rgw_user& owner = bucket_policy.get_owner().get_id();
if (owner.compare(s->user.user_id) != 0 &&
!bucket_policy.verify_permission(s->user.user_id, s->perm_mask, RGW_PERM_READ))
ret = -EACCES;
diff --git a/src/rgw/rgw_rados.cc b/src/rgw/rgw_rados.cc
index 67d8b555527..e03dae532e3 100644
--- a/src/rgw/rgw_rados.cc
+++ b/src/rgw/rgw_rados.cc
@@ -631,15 +631,16 @@ int RGWRados::log_usage(map<rgw_user_bucket, RGWUsageBatch>& usage_info)
return 0;
}
-int RGWRados::read_usage(string& user, uint64_t start_epoch, uint64_t end_epoch, uint32_t max_entries,
+int RGWRados::read_usage(rgw_user& user, uint64_t start_epoch, uint64_t end_epoch, uint32_t max_entries,
bool *is_truncated, RGWUsageIter& usage_iter, map<rgw_user_bucket, rgw_usage_log_entry>& usage)
{
uint32_t num = max_entries;
string hash, first_hash;
- usage_log_hash(cct, user, first_hash, 0);
+ string user_str = user.to_str();
+ usage_log_hash(cct, user_str, first_hash, 0);
if (usage_iter.index) {
- usage_log_hash(cct, user, hash, usage_iter.index);
+ usage_log_hash(cct, user_str, hash, usage_iter.index);
} else {
hash = first_hash;
}
@@ -650,7 +651,7 @@ int RGWRados::read_usage(string& user, uint64_t start_epoch, uint64_t end_epoch,
map<rgw_user_bucket, rgw_usage_log_entry> ret_usage;
map<rgw_user_bucket, rgw_usage_log_entry>::iterator iter;
- int ret = cls_obj_usage_log_read(hash, user, start_epoch, end_epoch, num,
+ int ret = cls_obj_usage_log_read(hash, user_str, start_epoch, end_epoch, num,
usage_iter.read_iter, ret_usage, is_truncated);
if (ret == -ENOENT)
goto next;
@@ -667,22 +668,23 @@ int RGWRados::read_usage(string& user, uint64_t start_epoch, uint64_t end_epoch,
next:
if (!*is_truncated) {
usage_iter.read_iter.clear();
- usage_log_hash(cct, user, hash, ++usage_iter.index);
+ usage_log_hash(cct, user_str, hash, ++usage_iter.index);
}
} while (num && !*is_truncated && hash != first_hash);
return 0;
}
-int RGWRados::trim_usage(string& user, uint64_t start_epoch, uint64_t end_epoch)
+int RGWRados::trim_usage(rgw_user& user, uint64_t start_epoch, uint64_t end_epoch)
{
uint32_t index = 0;
string hash, first_hash;
- usage_log_hash(cct, user, first_hash, index);
+ string user_str = user.to_str();
+ usage_log_hash(cct, user_str, first_hash, index);
hash = first_hash;
do {
- int ret = cls_obj_usage_log_trim(hash, user, start_epoch, end_epoch);
+ int ret = cls_obj_usage_log_trim(hash, user_str, start_epoch, end_epoch);
if (ret == -ENOENT)
goto next;
@@ -690,7 +692,7 @@ int RGWRados::trim_usage(string& user, uint64_t start_epoch, uint64_t end_epoch)
return ret;
next:
- usage_log_hash(cct, user, hash, ++index);
+ usage_log_hash(cct, user_str, hash, ++index);
} while (hash != first_hash);
return 0;
@@ -814,7 +816,7 @@ int RGWRados::create_pool(rgw_bucket& bucket)
* create a bucket with name bucket and the given list of attrs
* returns 0 on success, -ERR# otherwise.
*/
-int RGWRados::create_bucket(string& owner, rgw_bucket& bucket,
+int RGWRados::create_bucket(rgw_user& owner, rgw_bucket& bucket,
map<std::string, bufferlist>& attrs,
bool exclusive)
{
@@ -3556,7 +3558,7 @@ int RGWRados::cls_obj_complete_op(rgw_bucket& bucket, uint8_t op, string& tag, u
dir_meta.size = ent.size;
dir_meta.mtime = utime_t(ent.mtime, 0);
dir_meta.etag = ent.etag;
- dir_meta.owner = ent.owner;
+ dir_meta.owner = ent.owner.to_str();
dir_meta.owner_display_name = ent.owner_display_name;
dir_meta.content_type = ent.content_type;
dir_meta.category = category;
@@ -3861,7 +3863,7 @@ int RGWRados::check_disk_state(librados::IoCtx io_ctx,
list_state.meta.content_type = content_type;
if (astate->obj_tag.length() > 0)
list_state.meta.tag = astate->obj_tag.c_str();
- list_state.meta.owner = owner.get_id();
+ list_state.meta.owner = owner.get_id().to_str();
list_state.meta.owner_display_name = owner.get_display_name();
list_state.exists = true;
diff --git a/src/rgw/rgw_rados.h b/src/rgw/rgw_rados.h
index 6a2924365c9..a1ab01f694e 100644
--- a/src/rgw/rgw_rados.h
+++ b/src/rgw/rgw_rados.h
@@ -436,9 +436,9 @@ public:
// log bandwidth info
int log_usage(map<rgw_user_bucket, RGWUsageBatch>& usage_info);
- int read_usage(string& user, uint64_t start_epoch, uint64_t end_epoch, uint32_t max_entries,
+ int read_usage(rgw_user& user, uint64_t start_epoch, uint64_t end_epoch, uint32_t max_entries,
bool *is_truncated, RGWUsageIter& read_iter, map<rgw_user_bucket, rgw_usage_log_entry>& usage);
- int trim_usage(string& user, uint64_t start_epoch, uint64_t end_epoch);
+ int trim_usage(rgw_user& user, uint64_t start_epoch, uint64_t end_epoch);
/**
* get listing of the objects in a bucket.
@@ -463,7 +463,7 @@ public:
* create a bucket with name bucket and the given list of attrs
* returns 0 on success, -ERR# otherwise.
*/
- virtual int create_bucket(string& owner, rgw_bucket& bucket,
+ virtual int create_bucket(rgw_user& owner, rgw_bucket& bucket,
map<std::string,bufferlist>& attrs,
bool exclusive = true);
virtual int add_bucket_placement(std::string& new_pool);
diff --git a/src/rgw/rgw_rest.cc b/src/rgw/rgw_rest.cc
index 48d09d69ca6..596009b4b7c 100644
--- a/src/rgw/rgw_rest.cc
+++ b/src/rgw/rgw_rest.cc
@@ -334,12 +334,12 @@ void dump_time(struct req_state *s, const char *name, time_t *t)
s->formatter->dump_string(name, buf);
}
-void dump_owner(struct req_state *s, string& id, string& name, const char *section)
+void dump_owner(struct req_state *s, rgw_user& id, string& name, const char *section)
{
if (!section)
section = "Owner";
s->formatter->open_object_section(section);
- s->formatter->dump_string("ID", id);
+ s->formatter->dump_string("ID", id.to_str());
s->formatter->dump_string("DisplayName", name);
s->formatter->close_section();
}
diff --git a/src/rgw/rgw_rest.h b/src/rgw/rgw_rest.h
index d8e91a25054..12dd03568fa 100644
--- a/src/rgw/rgw_rest.h
+++ b/src/rgw/rgw_rest.h
@@ -309,7 +309,7 @@ extern void dump_errno(struct req_state *s, int ret);
extern void end_header(struct req_state *s, const char *content_type = NULL);
extern void dump_start(struct req_state *s);
extern void list_all_buckets_start(struct req_state *s);
-extern void dump_owner(struct req_state *s, string& id, string& name, const char *section = NULL);
+extern void dump_owner(struct req_state *s, rgw_user& id, string& name, const char *section = NULL);
extern void dump_content_length(struct req_state *s, uint64_t len);
extern void dump_etag(struct req_state *s, const char *etag);
extern void dump_last_modified(struct req_state *s, time_t t);
diff --git a/src/rgw/rgw_rest_bucket.cc b/src/rgw/rgw_rest_bucket.cc
index 73f85d7f292..241e92637a9 100644
--- a/src/rgw/rgw_rest_bucket.cc
+++ b/src/rgw/rgw_rest_bucket.cc
@@ -26,14 +26,16 @@ void RGWOp_Bucket_Info::execute()
bool fetch_stats;
- std::string uid;
std::string bucket;
- RESTArgs::get_string(s, "uid", uid, &uid);
+ string uid_str;
+
+ RESTArgs::get_string(s, "uid", uid_str, &uid_str);
+ rgw_user uid(uid_str);
+
RESTArgs::get_string(s, "bucket", bucket, &bucket);
RESTArgs::get_bool(s, "stats", false, &fetch_stats);
-
op_state.set_user_id(uid);
op_state.set_bucket_name(bucket);
op_state.set_fetch_stats(fetch_stats);
@@ -121,14 +123,15 @@ public:
void RGWOp_Bucket_Link::execute()
{
- std::string uid;
+ std::string uid_str;
std::string bucket;
RGWBucketAdminOpState op_state;
- RESTArgs::get_string(s, "uid", uid, &uid);
+ RESTArgs::get_string(s, "uid", uid_str, &uid_str);
RESTArgs::get_string(s, "bucket", bucket, &bucket);
+ rgw_user uid(uid_str);
op_state.set_user_id(uid);
op_state.set_bucket_name(bucket);
@@ -151,12 +154,14 @@ public:
void RGWOp_Bucket_Unlink::execute()
{
- std::string uid;
+ std::string uid_str;
std::string bucket;
RGWBucketAdminOpState op_state;
- RESTArgs::get_string(s, "uid", uid, &uid);
+ RESTArgs::get_string(s, "uid", uid_str, &uid_str);
+ rgw_user uid(uid_str);
+
RESTArgs::get_string(s, "bucket", bucket, &bucket);
op_state.set_user_id(uid);
diff --git a/src/rgw/rgw_rest_usage.cc b/src/rgw/rgw_rest_usage.cc
index 769e167019a..f2e0026fd55 100644
--- a/src/rgw/rgw_rest_usage.cc
+++ b/src/rgw/rgw_rest_usage.cc
@@ -22,12 +22,14 @@ public:
void RGWOp_Usage_Get::execute() {
map<std::string, bool> categories;
- string uid;
+ string uid_str;
uint64_t start, end;
bool show_entries;
bool show_summary;
- RESTArgs::get_string(s, "uid", uid, &uid);
+ RESTArgs::get_string(s, "uid", uid_str, &uid_str);
+ rgw_user uid(uid_str);
+
RESTArgs::get_epoch(s, "start", 0, &start);
RESTArgs::get_epoch(s, "end", (uint64_t)-1, &end);
RESTArgs::get_bool(s, "show-entries", true, &show_entries);
@@ -62,10 +64,12 @@ public:
};
void RGWOp_Usage_Delete::execute() {
- string uid;
+ string uid_str;
uint64_t start, end;
- RESTArgs::get_string(s, "uid", uid, &uid);
+ RESTArgs::get_string(s, "uid", uid_str, &uid_str);
+ rgw_user uid(uid_str);
+
RESTArgs::get_epoch(s, "start", 0, &start);
RESTArgs::get_epoch(s, "end", (uint64_t)-1, &end);
diff --git a/src/rgw/rgw_rest_user.cc b/src/rgw/rgw_rest_user.cc
index bdcce87bc95..81bb410b3dd 100644
--- a/src/rgw/rgw_rest_user.cc
+++ b/src/rgw/rgw_rest_user.cc
@@ -24,9 +24,10 @@ void RGWOp_User_Info::execute()
{
RGWUserAdminOpState op_state;
- std::string uid;
+ std::string uid_str;
- RESTArgs::get_string(s, "uid", uid, &uid);
+ RESTArgs::get_string(s, "uid", uid_str, &uid_str);
+ rgw_user uid(uid_str);
op_state.set_user_id(uid);
@@ -49,7 +50,7 @@ public:
void RGWOp_User_Create::execute()
{
- std::string uid;
+ std::string uid_str;
std::string display_name;
std::string email;
std::string access_key;
@@ -65,7 +66,9 @@ void RGWOp_User_Create::execute()
RGWUserAdminOpState op_state;
- RESTArgs::get_string(s, "uid", uid, &uid);
+ RESTArgs::get_string(s, "uid", uid_str, &uid_str);
+ rgw_user uid(uid_str);
+
RESTArgs::get_string(s, "display-name", display_name, &display_name);
RESTArgs::get_string(s, "email", email, &email);
RESTArgs::get_string(s, "access-key", access_key, &access_key);
@@ -132,7 +135,7 @@ public:
void RGWOp_User_Modify::execute()
{
- std::string uid;
+ std::string uid_str;
std::string display_name;
std::string email;
std::string access_key;
@@ -148,7 +151,9 @@ void RGWOp_User_Modify::execute()
RGWUserAdminOpState op_state;
- RESTArgs::get_string(s, "uid", uid, &uid);
+ RESTArgs::get_string(s, "uid", uid_str, &uid_str);
+ rgw_user uid(uid_str);
+
RESTArgs::get_string(s, "display-name", display_name, &display_name);
RESTArgs::get_string(s, "email", email, &email);
RESTArgs::get_string(s, "access-key", access_key, &access_key);
@@ -214,12 +219,14 @@ public:
void RGWOp_User_Remove::execute()
{
- std::string uid;
+ std::string uid_str;
bool purge_data;
RGWUserAdminOpState op_state;
- RESTArgs::get_string(s, "uid", uid, &uid);
+ RESTArgs::get_string(s, "uid", uid_str, &uid_str);
+ rgw_user uid(uid_str);
+
RESTArgs::get_bool(s, "purge-data", false, &purge_data);
// FIXME: no double checking
@@ -247,7 +254,7 @@ public:
void RGWOp_Subuser_Create::execute()
{
- std::string uid;
+ std::string uid_str;
std::string subuser;
std::string secret_key;
std::string perm_str;
@@ -261,7 +268,9 @@ void RGWOp_Subuser_Create::execute()
RGWUserAdminOpState op_state;
- RESTArgs::get_string(s, "uid", uid, &uid);
+ RESTArgs::get_string(s, "uid", uid_str, &uid_str);
+ rgw_user uid(uid_str);
+
RESTArgs::get_string(s, "subuser", subuser, &subuser);
RESTArgs::get_string(s, "secret-key", secret_key, &secret_key);
RESTArgs::get_string(s, "access", perm_str, &perm_str);
@@ -316,7 +325,7 @@ public:
void RGWOp_Subuser_Modify::execute()
{
- std::string uid;
+ std::string uid_str;
std::string subuser;
std::string secret_key;
std::string key_type_str;
@@ -329,7 +338,9 @@ void RGWOp_Subuser_Modify::execute()
bool gen_secret;
- RESTArgs::get_string(s, "uid", uid, &uid);
+ RESTArgs::get_string(s, "uid", uid_str, &uid_str);
+ rgw_user uid(uid_str);
+
RESTArgs::get_string(s, "subuser", subuser, &subuser);
RESTArgs::get_string(s, "secret-key", secret_key, &secret_key);
RESTArgs::get_string(s, "access", perm_str, &perm_str);
@@ -381,13 +392,15 @@ public:
void RGWOp_Subuser_Remove::execute()
{
- std::string uid;
+ std::string uid_str;
std::string subuser;
bool purge_keys;
RGWUserAdminOpState op_state;
- RESTArgs::get_string(s, "uid", uid, &uid);
+ RESTArgs::get_string(s, "uid", uid_str, &uid_str);
+ rgw_user uid(uid_str);
+
RESTArgs::get_string(s, "subuser", subuser, &subuser);
RESTArgs::get_bool(s, "purge-keys", true, &purge_keys);
@@ -420,7 +433,7 @@ public:
void RGWOp_Key_Create::execute()
{
- std::string uid;
+ std::string uid_str;
std::string subuser;
std::string access_key;
std::string secret_key;
@@ -431,7 +444,9 @@ void RGWOp_Key_Create::execute()
RGWUserAdminOpState op_state;
- RESTArgs::get_string(s, "uid", uid, &uid);
+ RESTArgs::get_string(s, "uid", uid_str, &uid_str);
+ rgw_user uid(uid_str);
+
RESTArgs::get_string(s, "subuser", subuser, &subuser);
RESTArgs::get_string(s, "access-key", access_key, &access_key);
RESTArgs::get_string(s, "secret-key", secret_key, &secret_key);
@@ -482,7 +497,7 @@ public:
void RGWOp_Key_Remove::execute()
{
- std::string uid;
+ std::string uid_str;
std::string subuser;
std::string access_key;
std::string key_type_str;
@@ -491,7 +506,9 @@ void RGWOp_Key_Remove::execute()
RGWUserAdminOpState op_state;
- RESTArgs::get_string(s, "uid", uid, &uid);
+ RESTArgs::get_string(s, "uid", uid_str, &uid_str);
+ rgw_user uid(uid_str);
+
RESTArgs::get_string(s, "subuser", subuser, &subuser);
RESTArgs::get_string(s, "access-key", access_key, &access_key);
RESTArgs::get_string(s, "key-type", key_type_str, &key_type_str);
@@ -534,12 +551,14 @@ public:
void RGWOp_Caps_Add::execute()
{
- std::string uid;
+ std::string uid_str;
std::string caps;
RGWUserAdminOpState op_state;
- RESTArgs::get_string(s, "uid", uid, &uid);
+ RESTArgs::get_string(s, "uid", uid_str, &uid_str);
+ rgw_user uid(uid_str);
+
RESTArgs::get_string(s, "user-caps", caps, &caps);
// FIXME: no double checking
@@ -568,12 +587,14 @@ public:
void RGWOp_Caps_Remove::execute()
{
- std::string uid;
+ std::string uid_str;
std::string caps;
RGWUserAdminOpState op_state;
- RESTArgs::get_string(s, "uid", uid, &uid);
+ RESTArgs::get_string(s, "uid", uid_str, &uid_str);
+ rgw_user uid(uid_str);
+
RESTArgs::get_string(s, "user-caps", caps, &caps);
// FIXME: no double checking
diff --git a/src/rgw/rgw_swift.cc b/src/rgw/rgw_swift.cc
index 59117dc876a..41660e82be6 100644
--- a/src/rgw/rgw_swift.cc
+++ b/src/rgw/rgw_swift.cc
@@ -658,7 +658,7 @@ bool RGWSwift::verify_swift_token(RGWRados *store, req_state *s)
return false;
}
- s->swift_user = info.user;
+ s->swift_user = info.user.to_str();
s->swift_groups = info.auth_groups;
string swift_user = s->swift_user;
diff --git a/src/rgw/rgw_swift.h b/src/rgw/rgw_swift.h
index febc2675c27..772a545df88 100644
--- a/src/rgw/rgw_swift.h
+++ b/src/rgw/rgw_swift.h
@@ -10,7 +10,7 @@ class RGWRados;
struct rgw_swift_auth_info {
int status;
string auth_groups;
- string user;
+ rgw_user user;
string display_name;
long long ttl;
diff --git a/src/rgw/rgw_usage.cc b/src/rgw/rgw_usage.cc
index f5016913b68..57ce01381fa 100644
--- a/src/rgw/rgw_usage.cc
+++ b/src/rgw/rgw_usage.cc
@@ -28,7 +28,7 @@ static void dump_usage_categories_info(Formatter *formatter, const rgw_usage_log
formatter->close_section(); // categories
}
-int RGWUsage::show(RGWRados *store, string& uid, uint64_t start_epoch,
+int RGWUsage::show(RGWRados *store, rgw_user& uid, uint64_t start_epoch,
uint64_t end_epoch, bool show_log_entries, bool show_log_sum,
map<string, bool> *categories,
RGWFormatterFlusher& flusher)
@@ -133,7 +133,7 @@ int RGWUsage::show(RGWRados *store, string& uid, uint64_t start_epoch,
return 0;
}
-int RGWUsage::trim(RGWRados *store, string& uid, uint64_t start_epoch,
+int RGWUsage::trim(RGWRados *store, rgw_user& uid, uint64_t start_epoch,
uint64_t end_epoch)
{
return store->trim_usage(uid, start_epoch, end_epoch);
diff --git a/src/rgw/rgw_usage.h b/src/rgw/rgw_usage.h
index 76ae0f54458..f54393f4d1b 100644
--- a/src/rgw/rgw_usage.h
+++ b/src/rgw/rgw_usage.h
@@ -13,12 +13,12 @@ class RGWRados;
class RGWUsage
{
public:
- static int show(RGWRados *store, std::string& uid, uint64_t start_epoch,
+ static int show(RGWRados *store, rgw_user& uid, uint64_t start_epoch,
uint64_t end_epoch, bool show_log_entries, bool show_log_sum,
std::map<std::string, bool> *categories,
RGWFormatterFlusher& flusher);
- static int trim(RGWRados *store, std::string& uid, uint64_t start_epoch,
+ static int trim(RGWRados *store, rgw_user& uid, uint64_t start_epoch,
uint64_t end_epoch);
};
diff --git a/src/rgw/rgw_user.cc b/src/rgw/rgw_user.cc
index 781fce46eda..8174d510387 100644
--- a/src/rgw/rgw_user.cc
+++ b/src/rgw/rgw_user.cc
@@ -33,7 +33,7 @@ void rgw_get_anon_user(RGWUserInfo& info)
bool rgw_user_is_authenticated(RGWUserInfo& info)
{
- return (info.user_id != RGW_USER_ANON_ID);
+ return (info.user_id.id != RGW_USER_ANON_ID);
}
/**
@@ -86,7 +86,10 @@ int rgw_store_user_info(RGWRados *store, RGWUserInfo& info, RGWUserInfo *old_inf
::encode(ui, data_bl);
::encode(info, data_bl);
- ret = rgw_put_system_obj(store, store->zone.user_uid_pool, info.user_id, data_bl.c_str(), data_bl.length(), exclusive);
+ string oid;
+ info.user_id.to_str(oid);
+
+ ret = rgw_put_system_obj(store, store->zone.user_uid_pool, oid, data_bl.c_str(), data_bl.length(), exclusive);
if (ret < 0)
return ret;
@@ -151,12 +154,14 @@ int rgw_get_user_info_from_index(RGWRados *store, string& key, rgw_bucket& bucke
* Given an email, finds the user info associated with it.
* returns: 0 on success, -ERR# on failure (including nonexistence)
*/
-int rgw_get_user_info_by_uid(RGWRados *store, string& uid, RGWUserInfo& info)
+int rgw_get_user_info_by_uid(RGWRados *store, rgw_user& uid, RGWUserInfo& info)
{
bufferlist bl;
RGWUID user_id;
- int ret = rgw_get_obj(store, NULL, store->zone.user_uid_pool, uid, bl);
+ string oid = uid.to_str();
+
+ int ret = rgw_get_obj(store, NULL, store->zone.user_uid_pool, oid, bl);
if (ret < 0)
return ret;
@@ -212,9 +217,11 @@ int rgw_remove_key_index(RGWRados *store, RGWAccessKey& access_key)
return ret;
}
-int rgw_remove_uid_index(RGWRados *store, string& uid)
+int rgw_remove_uid_index(RGWRados *store, rgw_user& uid)
{
- rgw_obj obj(store->zone.user_uid_pool, uid);
+ string oid = uid.to_str();
+
+ rgw_obj obj(store->zone.user_uid_pool, oid);
int ret = store->delete_obj(NULL, obj);
return ret;
}
@@ -306,8 +313,11 @@ int rgw_delete_user(RGWRados *store, RGWUserInfo& info) {
ldout(store->ctx(), 0) << "ERROR: could not remove " << info.user_id << ":" << uid_bucks << ", should be fixed (err=" << ret << ")" << dendl;
return ret;
}
+
+ string oid;
+ info.user_id.to_str(oid);
- rgw_obj uid_obj(store->zone.user_uid_pool, info.user_id);
+ rgw_obj uid_obj(store->zone.user_uid_pool, oid);
ldout(store->ctx(), 10) << "removing user index: " << info.user_id << dendl;
ret = store->delete_obj(NULL, uid_obj);
if (ret < 0 && ret != -ENOENT) {
@@ -413,10 +423,15 @@ static bool remove_old_indexes(RGWRados *store,
int ret;
bool success = true;
- if (!old_info.user_id.empty() && old_info.user_id.compare(new_info.user_id) != 0) {
+ if (!old_info.user_id.empty() &&
+ old_info.user_id.compare(new_info.user_id) != 0) {
+ if (old_info.user_id.tenant != new_info.user_id.tenant) {
+ ldout(store->ctx(), 0) << "ERROR: tenant mismatch: " << old_info.user_id.tenant << " != " << new_info.user_id.tenant << dendl;
+ return false;
+ }
ret = rgw_remove_uid_index(store, old_info.user_id);
if (ret < 0 && ret != -ENOENT) {
- set_err_msg(err_msg, "ERROR: could not remove index for uid " + old_info.user_id);
+ set_err_msg(err_msg, "ERROR: could not remove index for uid " + old_info.user_id.to_str());
success = false;
}
}
@@ -462,7 +477,9 @@ static void dump_subusers_info(Formatter *f, RGWUserInfo &info)
for (uiter = info.subusers.begin(); uiter != info.subusers.end(); ++uiter) {
RGWSubUser& u = uiter->second;
f->open_object_section("user");
- f->dump_format("id", "%s:%s", info.user_id.c_str(), u.name.c_str());
+ string s;
+ info.user_id.to_str(s);
+ f->dump_format("id", "%s:%s", s.c_str(), u.name.c_str());
char buf[256];
rgw_perm_to_str(u.perm_mask, buf, sizeof(buf));
f->dump_string("permissions", buf);
@@ -480,7 +497,9 @@ static void dump_access_keys_info(Formatter *f, RGWUserInfo &info)
const char *sep = (k.subuser.empty() ? "" : ":");
const char *subuser = (k.subuser.empty() ? "" : k.subuser.c_str());
f->open_object_section("key");
- f->dump_format("user", "%s%s%s", info.user_id.c_str(), sep, subuser);
+ string s;
+ info.user_id.to_str(s);
+ f->dump_format("user", "%s%s%s", s.c_str(), sep, subuser);
f->dump_string("access_key", k.id);
f->dump_string("secret_key", k.key);
f->close_section();
@@ -497,7 +516,9 @@ static void dump_swift_keys_info(Formatter *f, RGWUserInfo &info)
const char *sep = (k.subuser.empty() ? "" : ":");
const char *subuser = (k.subuser.empty() ? "" : k.subuser.c_str());
f->open_object_section("key");
- f->dump_format("user", "%s%s%s", info.user_id.c_str(), sep, subuser);
+ string s;
+ info.user_id.to_str(s);
+ f->dump_format("user", "%s%s%s", s.c_str(), sep, subuser);
f->dump_string("secret_key", k.key);
f->close_section();
}
@@ -508,7 +529,8 @@ static void dump_user_info(Formatter *f, RGWUserInfo &info)
{
f->open_object_section("user_info");
- f->dump_string("user_id", info.user_id);
+ f->dump_string("tenant", info.user_id.tenant);
+ f->dump_string("user_id", info.user_id.id);
f->dump_string("display_name", info.display_name);
f->dump_string("email", info.user_email);
f->dump_int("suspended", (int)info.suspended);
@@ -552,7 +574,7 @@ int RGWAccessKeyPool::init(RGWUserAdminOpState& op_state)
return -EINVAL;
}
- std::string uid = op_state.get_user_id();
+ rgw_user& uid = op_state.get_user_id();
if (uid.compare(RGW_USER_ANON_ID) == 0) {
keys_allowed = false;
return -EACCES;
@@ -1012,7 +1034,7 @@ int RGWSubUserPool::init(RGWUserAdminOpState& op_state)
return -EINVAL;
}
- std::string uid = op_state.get_user_id();
+ rgw_user& uid = op_state.get_user_id();
if (uid.compare(RGW_USER_ANON_ID) == 0) {
subusers_allowed = false;
return -EACCES;
@@ -1296,8 +1318,8 @@ int RGWUserCapPool::init(RGWUserAdminOpState& op_state)
return -EINVAL;
}
- std::string uid = op_state.get_user_id();
- if (uid == RGW_USER_ANON_ID) {
+ rgw_user& uid = op_state.get_user_id();
+ if (uid.compare(RGW_USER_ANON_ID) == 0) {
caps_allowed = false;
return -EACCES;
}
@@ -1449,7 +1471,7 @@ int RGWUser::init(RGWUserAdminOpState& op_state)
{
bool found = false;
std::string swift_user;
- std::string uid = op_state.get_user_id();
+ rgw_user& uid = op_state.get_user_id();
std::string user_email = op_state.get_user_email();
std::string access_key = op_state.get_access_key();
std::string subuser = op_state.get_subuser();
@@ -1565,7 +1587,7 @@ int RGWUser::check_op(RGWUserAdminOpState& op_state, std::string *err_msg)
bool same_id;
bool populated;
//bool existing_email = false; // this check causes a fault
- std::string op_id = op_state.get_user_id();
+ rgw_user& op_id = op_state.get_user_id();
std::string op_email = op_state.get_user_email();
RGWUserInfo user_info;
@@ -1579,8 +1601,8 @@ int RGWUser::check_op(RGWUserAdminOpState& op_state, std::string *err_msg)
}
if (populated && !same_id) {
- set_err_msg(err_msg, "user id mismatch, operation id: " + op_id\
- + " does not match: " + user_id);
+ set_err_msg(err_msg, "user id mismatch, operation id: " + op_id.to_str()
+ + " does not match: " + user_id.to_str());
return -EINVAL;
}
@@ -1596,7 +1618,7 @@ int RGWUser::execute_add(RGWUserAdminOpState& op_state, std::string *err_msg)
RGWUserInfo user_info;
- std::string uid = op_state.get_user_id();
+ rgw_user& uid = op_state.get_user_id();
std::string user_email = op_state.get_user_email();
std::string display_name = op_state.get_display_name();
@@ -1607,7 +1629,7 @@ int RGWUser::execute_add(RGWUserAdminOpState& op_state, std::string *err_msg)
return execute_modify(op_state, err_msg);
}
- set_err_msg(err_msg, "user: " + op_state.user_id + " exists");
+ set_err_msg(err_msg, "user: " + op_state.user_id.to_str() + " exists");
return -EEXIST;
}
@@ -1705,7 +1727,7 @@ int RGWUser::execute_remove(RGWUserAdminOpState& op_state, std::string *err_msg)
int ret;
bool purge_data = op_state.will_purge_data();
- std::string uid = op_state.get_user_id();
+ rgw_user& uid = op_state.get_user_id();
RGWUserInfo user_info = op_state.get_user_info();
if (!op_state.has_existing_user()) {
@@ -1804,7 +1826,7 @@ int RGWUser::execute_modify(RGWUserAdminOpState& op_state, std::string *err_msg)
}
// ensure that we can modify the user's attributes
- if (user_id == RGW_USER_ANON_ID) {
+ if (user_id.compare(RGW_USER_ANON_ID) == 0) {
set_err_msg(err_msg, "unable to modify anonymous user's info");
return -EACCES;
}
@@ -1819,7 +1841,7 @@ int RGWUser::execute_modify(RGWUserAdminOpState& op_state, std::string *err_msg)
// make sure we are not adding a duplicate email
if (!same_email) {
ret = rgw_get_user_info_by_email(store, op_email, duplicate_check);
- if (ret >= 0 && duplicate_check.user_id != user_id) {
+ if (ret >= 0 && duplicate_check.user_id.compare(user_id) != 0) {
set_err_msg(err_msg, "cannot add duplicate email");
return -EEXIST;
}
@@ -1861,7 +1883,7 @@ int RGWUser::execute_modify(RGWUserAdminOpState& op_state, std::string *err_msg)
do {
ret = rgw_read_user_buckets(store, user_id, buckets, marker, max_buckets, false);
if (ret < 0) {
- set_err_msg(err_msg, "could not get buckets for uid: " + user_id);
+ set_err_msg(err_msg, "could not get buckets for uid: " + user_id.to_str());
return ret;
}
diff --git a/src/rgw/rgw_user.h b/src/rgw/rgw_user.h
index 42e6097dddf..941e08a006c 100644
--- a/src/rgw/rgw_user.h
+++ b/src/rgw/rgw_user.h
@@ -28,12 +28,16 @@ using namespace std;
*/
struct RGWUID
{
- string user_id;
+ rgw_user user_id;
void encode(bufferlist& bl) const {
- ::encode(user_id, bl);
+ string s;
+ user_id.to_str(s);
+ ::encode(s, bl);
}
void decode(bufferlist::iterator& bl) {
- ::decode(user_id, bl);
+ string s;
+ ::decode(s, bl);
+ user_id.from_str(s);
}
};
WRITE_CLASS_ENCODER(RGWUID)
@@ -56,7 +60,7 @@ extern int rgw_store_user_info(RGWRados *store, RGWUserInfo& info, RGWUserInfo *
* Given an email, finds the user info associated with it.
* returns: 0 on success, -ERR# on failure (including nonexistence)
*/
-extern int rgw_get_user_info_by_uid(RGWRados *store, string& user_id, RGWUserInfo& info);
+extern int rgw_get_user_info_by_uid(RGWRados *store, rgw_user& user_id, RGWUserInfo& info);
/**
* Given an swift username, finds the user info associated with it.
* returns: 0 on success, -ERR# on failure (including nonexistence)
@@ -100,7 +104,7 @@ extern int rgw_delete_user(RGWRados *store, RGWUserInfo& user);
* remove the different indexes
*/
extern int rgw_remove_key_index(RGWRados *store, RGWAccessKey& access_key);
-extern int rgw_remove_uid_index(RGWRados *store, string& uid);
+extern int rgw_remove_uid_index(RGWRados *store, rgw_user& uid);
extern int rgw_remove_email_index(RGWRados *store, string& email);
extern int rgw_remove_swift_name_index(RGWRados *store, string& swift_name);
@@ -133,7 +137,7 @@ enum RGWUserId {
struct RGWUserAdminOpState {
// user attributes
RGWUserInfo info;
- std::string user_id;
+ rgw_user user_id;
std::string user_email;
std::string display_name;
uint32_t max_buckets;
@@ -198,7 +202,7 @@ struct RGWUserAdminOpState {
gen_secret = false;
key_op = true;
}
- void set_user_id(std::string& id) {
+ void set_user_id(rgw_user& id) {
if (id.empty())
return;
@@ -322,7 +326,7 @@ struct RGWUserAdminOpState {
uint32_t get_max_buckets() { return max_buckets; };
uint32_t get_op_mask() { return op_mask; };
- std::string get_user_id() { return user_id; };
+ rgw_user& get_user_id() { return user_id; };
std::string get_subuser() { return subuser; };
std::string get_access_key() { return id; };
std::string get_secret_key() { return key; };
@@ -339,10 +343,11 @@ struct RGWUserAdminOpState {
RGWUserCaps *get_caps_obj() { return &info.caps; };
std::string build_default_swift_kid() {
- if (user_id.empty() || subuser.empty())
+ if (user_id.id.empty() || subuser.empty())
return "";
- std::string kid = user_id;
+ string kid;
+ user_id.to_str(kid);
kid.append(":");
kid.append(subuser);
@@ -350,10 +355,11 @@ struct RGWUserAdminOpState {
}
std::string generate_subuser() {
- if (user_id.empty())
+ if (user_id.id.empty())
return "";
- std::string generated_subuser = user_id;
+ std::string generated_subuser;
+ user_id.to_str(generated_subuser);
std::string rand_suffix;
int sub_buf_size = RAND_SUBUSER_LEN + 1;
@@ -372,7 +378,7 @@ struct RGWUserAdminOpState {
return generated_subuser;
}
- RGWUserAdminOpState() : user_id(RGW_USER_ANON_ID), user_email(""), display_name(""), id(""), key ("")
+ RGWUserAdminOpState() : user_id(RGW_USER_ANON_ID)
{
max_buckets = RGW_DEFAULT_MAX_BUCKETS;
key_type = -1;
@@ -416,7 +422,7 @@ class RGWAccessKeyPool
RGWUser *user;
std::map<std::string, int, ltstr_nocase> key_type_map;
- std::string user_id;
+ rgw_user user_id;
RGWRados *store;
map<std::string, RGWAccessKey> *swift_keys;
@@ -458,7 +464,7 @@ class RGWSubUserPool
{
RGWUser *user;
- string user_id;
+ rgw_user user_id;
RGWRados *store;
bool subusers_allowed;
@@ -520,7 +526,7 @@ private:
RGWUserInfo old_info;
RGWRados *store;
- string user_id;
+ rgw_user user_id;
bool info_stored;
void set_populated() { info_stored = true; };