1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
|
#ifndef CEPH_RGW_USER_H
#define CEPH_RGW_USER_H
#include "include/types.h"
#include "rgw_common.h"
#include "rgw_tools.h"
using namespace std;
#define RGW_USER_ANON_ID "anonymous"
/**
* A string wrapper that includes encode/decode functions
* for easily accessing a UID in all forms
*/
struct RGWUID
{
string user_id;
void encode(bufferlist& bl) const {
::encode(user_id, bl);
}
void decode(bufferlist::iterator& bl) {
::decode(user_id, bl);
}
};
WRITE_CLASS_ENCODER(RGWUID)
/**
* Get the anonymous (ie, unauthenticated) user info.
*/
extern void rgw_get_anon_user(RGWUserInfo& info);
/**
* verify that user is an actual user, and not the anonymous user
*/
extern bool rgw_user_is_authenticated(RGWUserInfo& info);
/**
* Save the given user information to storage.
* Returns: 0 on success, -ERR# on failure.
*/
extern int rgw_store_user_info(RGWRados *store, RGWUserInfo& info, bool exclusive);
/**
* 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);
/**
* Given an swift username, finds the user info associated with it.
* returns: 0 on success, -ERR# on failure (including nonexistence)
*/
extern int rgw_get_user_info_by_email(RGWRados *store, string& email, RGWUserInfo& info);
/**
* Given an swift username, finds the user info associated with it.
* returns: 0 on success, -ERR# on failure (including nonexistence)
*/
extern int rgw_get_user_info_by_swift(RGWRados *store, string& swift_name, RGWUserInfo& info);
/**
* Given an access key, finds the user info associated with it.
* returns: 0 on success, -ERR# on failure (including nonexistence)
*/
extern int rgw_get_user_info_by_access_key(RGWRados *store, string& access_key, RGWUserInfo& info);
/**
* Given an RGWUserInfo, deletes the user and its bucket ACLs.
*/
extern int rgw_delete_user(RGWRados *store, RGWUserInfo& user);
/**
* Store a list of the user's buckets, with associated functinos.
*/
class RGWUserBuckets
{
map<string, RGWBucketEnt> buckets;
public:
RGWUserBuckets() {}
void encode(bufferlist& bl) const {
::encode(buckets, bl);
}
void decode(bufferlist::iterator& bl) {
::decode(buckets, bl);
}
/**
* Check if the user owns a bucket by the given name.
*/
bool owns(string& name) {
map<string, RGWBucketEnt>::iterator iter;
iter = buckets.find(name);
return (iter != buckets.end());
}
/**
* Add a (created) bucket to the user's bucket list.
*/
void add(RGWBucketEnt& bucket) {
buckets[bucket.bucket.name] = bucket;
}
/**
* Remove a bucket from the user's list by name.
*/
void remove(string& name) {
map<string, RGWBucketEnt>::iterator iter;
iter = buckets.find(name);
if (iter != buckets.end()) {
buckets.erase(iter);
}
}
/**
* Get the user's buckets as a map.
*/
map<string, RGWBucketEnt>& get_buckets() { return buckets; }
/**
* Cleanup data structure
*/
void clear() { buckets.clear(); }
size_t count() { return buckets.size(); }
};
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, bool need_stats);
/**
* Store the set of buckets associated with a user.
* 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_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);
/*
* 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_email_index(RGWRados *store, string& email);
extern int rgw_remove_swift_name_index(RGWRados *store, string& swift_name);
#endif
|