diff options
author | Yehuda Sadeh <yehuda@hq.newdream.net> | 2011-04-18 08:56:52 -0700 |
---|---|---|
committer | Yehuda Sadeh <yehuda@hq.newdream.net> | 2011-04-18 08:56:52 -0700 |
commit | 796528c3db66d63d0bd75c880cb871d5e4f0322a (patch) | |
tree | 5a09fbe927a625b31877bd01e4e11ec781aa25cd /src | |
parent | d8fe208d06530e43eb1bdee74687ffedd628be98 (diff) | |
download | ceph-796528c3db66d63d0bd75c880cb871d5e4f0322a.tar.gz |
rgw: remove get_user_info() and clean up
rename all the get_uid_by_* to get_user_info_by_*, remove get_user_info()
and call the appropriate function instead (either the by_uid or by_access_key).
Diffstat (limited to 'src')
-rw-r--r-- | src/rgw/rgw_admin.cc | 15 | ||||
-rw-r--r-- | src/rgw/rgw_op.cc | 7 | ||||
-rw-r--r-- | src/rgw/rgw_os.cc | 6 | ||||
-rw-r--r-- | src/rgw/rgw_os_auth.cc | 6 | ||||
-rw-r--r-- | src/rgw/rgw_rest_s3.cc | 2 | ||||
-rw-r--r-- | src/rgw/rgw_user.cc | 80 | ||||
-rw-r--r-- | src/rgw/rgw_user.h | 22 |
7 files changed, 49 insertions, 89 deletions
diff --git a/src/rgw/rgw_admin.cc b/src/rgw/rgw_admin.cc index c87a0f8cbec..41a0975011b 100644 --- a/src/rgw/rgw_admin.cc +++ b/src/rgw/rgw_admin.cc @@ -245,14 +245,12 @@ int main(int argc, char **argv) return 5; //EIO } - string user_id_str; - if (opt_cmd != OPT_USER_CREATE && opt_cmd != OPT_LOG_SHOW && !user_id) { bool found = false; string s; if (user_email) { s = user_email; - if (rgw_get_uid_by_email(s, user_id_str, info) >= 0) { + if (rgw_get_user_info_by_email(s, info) >= 0) { found = true; } else { cerr << "could not find user by specified email" << std::endl; @@ -260,7 +258,7 @@ int main(int argc, char **argv) } if (!found && access_key) { s = access_key; - if (rgw_get_uid_by_access_key(s, user_id_str, info) >= 0) { + if (rgw_get_user_info_by_access_key(s, info) >= 0) { found = true; } else { cerr << "could not find user by specified access key" << std::endl; @@ -268,13 +266,13 @@ int main(int argc, char **argv) } if (!found && openstack_user) { s = openstack_user; - if (rgw_get_uid_by_openstack(s, user_id_str, info) >= 0) { + if (rgw_get_user_info_by_openstack(s, info) >= 0) { found = true; } else cerr << "could not find user by specified openstack username" << std::endl; } if (found) - user_id = user_id_str.c_str(); + user_id = info.user_id.c_str(); } @@ -289,7 +287,7 @@ int main(int argc, char **argv) if (opt_cmd != OPT_USER_CREATE && info.user_id.empty() && - rgw_get_user_info(user_id_str, info) < 0) { + rgw_get_user_info_by_uid(user_id_str, info) < 0) { cerr << "error reading user info, aborting" << std::endl; exit(1); } @@ -316,7 +314,6 @@ int main(int argc, char **argv) if (!access_key) { RGWUserInfo duplicate_check; string duplicate_check_id; - string uid; do { ret = gen_rand_alphanumeric(public_id_buf, sizeof(public_id_buf)); if (ret < 0) { @@ -325,7 +322,7 @@ int main(int argc, char **argv) } access_key = public_id_buf; duplicate_check_id = access_key; - } while (!rgw_get_uid_by_access_key(duplicate_check_id, uid, duplicate_check)); + } while (!rgw_get_user_info_by_access_key(duplicate_check_id, duplicate_check)); } } diff --git a/src/rgw/rgw_op.cc b/src/rgw/rgw_op.cc index 32605b661ff..94466a8005c 100644 --- a/src/rgw/rgw_op.cc +++ b/src/rgw/rgw_op.cc @@ -606,7 +606,7 @@ static int rebuild_policy(RGWAccessControlPolicy& src, RGWAccessControlPolicy& d return -EINVAL; RGWUserInfo owner_info; - if (rgw_get_user_info(owner->get_id(), owner_info) < 0) { + if (rgw_get_user_info_by_uid(owner->get_id(), owner_info) < 0) { RGW_LOG(10) << "owner info does not exist" << endl; return -EINVAL; } @@ -630,17 +630,18 @@ static int rebuild_policy(RGWAccessControlPolicy& src, RGWAccessControlPolicy& d { string email = src_grant->get_id(); RGW_LOG(10) << "grant user email=" << email << endl; - if (rgw_get_uid_by_email(email, id, grant_user) < 0) { + if (rgw_get_user_info_by_email(email, grant_user) < 0) { RGW_LOG(10) << "grant user email not found or other error" << endl; break; } + id = grant_user.user_id; } case ACL_TYPE_CANON_USER: { if (type.get_type() == ACL_TYPE_CANON_USER) id = src_grant->get_id(); - if (grant_user.user_id.empty() && rgw_get_user_info(id, grant_user) < 0) { + if (grant_user.user_id.empty() && rgw_get_user_info_by_uid(id, grant_user) < 0) { RGW_LOG(10) << "grant user does not exist:" << id << endl; } else { ACLPermission& perm = src_grant->get_permission(); diff --git a/src/rgw/rgw_os.cc b/src/rgw/rgw_os.cc index 04aabf5127e..b313f9a7b80 100644 --- a/src/rgw/rgw_os.cc +++ b/src/rgw/rgw_os.cc @@ -113,14 +113,12 @@ bool rgw_verify_os_token(req_state *s) RGW_LOG(0) << "openstack user=" << s->os_user << std::endl; - string auth_id; - - if (rgw_get_uid_by_openstack(openstack_user, auth_id, s->user) < 0) { + if (rgw_get_user_info_by_openstack(openstack_user, s->user) < 0) { RGW_LOG(0) << "couldn't map openstack user" << std::endl; return false; } - RGW_LOG(0) << "auth_id=" << auth_id << std::endl; + RGW_LOG(0) << "user_id=" << s->user.user_id << " access_key=" << s->user.access_key << std::endl; return true; } diff --git a/src/rgw/rgw_os_auth.cc b/src/rgw/rgw_os_auth.cc index dbb94d15239..b1da14cb7ed 100644 --- a/src/rgw/rgw_os_auth.cc +++ b/src/rgw/rgw_os_auth.cc @@ -113,7 +113,6 @@ int rgw_os_verify_signed_token(const char *token, RGWUserInfo& info) uint64_t nonce; utime_t expiration; string os_user; - string s3_user; try { ::decode(os_user, iter); @@ -128,7 +127,7 @@ int rgw_os_verify_signed_token(const char *token, RGWUserInfo& info) return -EPERM; } - if ((ret = rgw_get_uid_by_openstack(os_user, s3_user, info)) < 0) + if ((ret = rgw_get_user_info_by_openstack(os_user, info)) < 0) return ret; RGW_LOG(0) << "os_user=" << os_user << std::endl; @@ -165,7 +164,6 @@ void RGW_OS_Auth_Get::execute() const char *os_url = FCGX_GetParam("RGW_OPENSTACK_URL", s->fcgx->envp); string user_str = user; - string user_id; RGWUserInfo info; bufferlist bl; @@ -178,7 +176,7 @@ void RGW_OS_Auth_Get::execute() if (!key || !user) goto done; - if ((ret = rgw_get_uid_by_openstack(user_str, user_id, info)) < 0) + if ((ret = rgw_get_user_info_by_openstack(user_str, info)) < 0) goto done; if (info.openstack_key.compare(key) != 0) { diff --git a/src/rgw/rgw_rest_s3.cc b/src/rgw/rgw_rest_s3.cc index 91f46c96b94..9bcf459b118 100644 --- a/src/rgw/rgw_rest_s3.cc +++ b/src/rgw/rgw_rest_s3.cc @@ -414,7 +414,7 @@ bool RGWHandler_REST_S3::authorize(struct req_state *s) } /* first get the user info */ - if (rgw_get_user_info(auth_id, s->user) < 0) { + if (rgw_get_user_info_by_access_key(auth_id, s->user) < 0) { RGW_LOG(5) << "error reading user info, uid=" << auth_id << " can't authenticate" << endl; return false; } diff --git a/src/rgw/rgw_user.cc b/src/rgw/rgw_user.cc index fc7a73505a0..4b5b7e4ca4d 100644 --- a/src/rgw/rgw_user.cc +++ b/src/rgw/rgw_user.cc @@ -20,45 +20,6 @@ static string ui_uid_bucket = USER_INFO_UID_BUCKET_NAME; string rgw_root_bucket = RGW_ROOT_BUCKET; #define READ_CHUNK_LEN (16 * 1024) -/** - * Get the info for a user out of storage. - * Returns: 0 on success, -ERR# on failure - */ -int rgw_get_user_info(string user_id, RGWUserInfo& info) -{ - bufferlist bl; - int ret; - char *data; - struct rgw_err err; - void *handle = NULL; - int request_len = READ_CHUNK_LEN; - time_t lastmod; - bufferlist::iterator iter; - ret = rgwstore->prepare_get_obj(ui_uid_bucket, user_id, 0, NULL, NULL, NULL, NULL, &lastmod, NULL, NULL, NULL, &handle, &err); - if (ret < 0) - return ret; - do { // we want to read the whole user info in one chunk to avoid any possible race - ret = rgwstore->get_obj(&handle, ui_uid_bucket, user_id, &data, 0, request_len - 1); - if (ret < 0) { - goto done; - } - if (ret < request_len) - break; - - free(data); - request_len *= 2; - } while (true); - - bl.append(data, ret); - free(data); - - iter = bl.begin(); - info.decode(iter); - ret = 0; -done: - rgwstore->finish_get_obj(&handle); - return ret; -} /** * Get the anonymous (ie, unauthenticated) user info. @@ -93,17 +54,15 @@ int rgw_store_user_info(RGWUserInfo& info) { bufferlist bl; info.encode(bl); - const char *data = bl.c_str(); string md5; int ret; map<string,bufferlist> attrs; if (info.openstack_name.size()) { /* check if openstack mapping exists */ - string os_uid; RGWUserInfo inf; - int r = rgw_get_uid_by_openstack(info.openstack_name, os_uid, inf); - if (r >= 0 && os_uid.compare(info.user_id) != 0) { + int r = rgw_get_user_info_by_openstack(info.openstack_name, inf); + if (r >= 0 && inf.user_id.compare(info.user_id) != 0) { RGW_LOG(0) << "can't store user info, openstack id already mapped to another user" << std::endl; return -EEXIST; } @@ -111,10 +70,9 @@ int rgw_store_user_info(RGWUserInfo& info) if (info.access_key.size()) { /* check if openstack mapping exists */ - string uid; RGWUserInfo inf; - int r = rgw_get_uid_by_access_key(info.access_key, uid, inf); - if (r >= 0 && uid.compare(info.user_id) != 0) { + int r = rgw_get_user_info_by_access_key(info.access_key, inf); + if (r >= 0 && inf.user_id.compare(info.user_id) != 0) { RGW_LOG(0) << "can't store user info, access key already mapped to another user" << std::endl; return -EEXIST; } @@ -148,7 +106,7 @@ int rgw_store_user_info(RGWUserInfo& info) return ret; } -int rgw_get_uid_from_index(string& key, string& bucket, string& user_id, RGWUserInfo& info) +int rgw_get_user_info_from_index(string& key, string& bucket, RGWUserInfo& info) { bufferlist bl; int ret; @@ -178,7 +136,6 @@ int rgw_get_uid_from_index(string& key, string& bucket, string& user_id, RGWUser iter = bl.begin(); ::decode(uid, iter); - user_id = uid.user_id; if (!iter.end()) { info.decode(iter); } @@ -189,30 +146,39 @@ done: } /** - * Given an email, finds the user_id associated with it. + * 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(string& uid, RGWUserInfo& info) +{ + return rgw_get_user_info_from_index(uid, ui_uid_bucket, info); +} + +/** + * Given an email, finds the user info associated with it. * returns: 0 on success, -ERR# on failure (including nonexistence) */ -int rgw_get_uid_by_email(string& email, string& user_id, RGWUserInfo& info) +int rgw_get_user_info_by_email(string& email, RGWUserInfo& info) { - return rgw_get_uid_from_index(email, ui_email_bucket, user_id, info); + return rgw_get_user_info_from_index(email, ui_email_bucket, info); } /** - * Given an openstack username, finds the user_id associated with it. + * Given an openstack username, finds the user_info associated with it. * returns: 0 on success, -ERR# on failure (including nonexistence) */ -extern int rgw_get_uid_by_openstack(string& openstack_name, string& user_id, RGWUserInfo& info) +extern int rgw_get_user_info_by_openstack(string& openstack_name, RGWUserInfo& info) { - return rgw_get_uid_from_index(openstack_name, ui_openstack_bucket, user_id, info); + return rgw_get_user_info_from_index(openstack_name, ui_openstack_bucket, info); } /** - * Given an access key, finds the user_id associated with it. + * Given an access key, finds the user info associated with it. * returns: 0 on success, -ERR# on failure (including nonexistence) */ -extern int rgw_get_uid_by_access_key(string& access_key, string& user_id, RGWUserInfo& info) +extern int rgw_get_user_info_by_access_key(string& access_key, RGWUserInfo& info) { - return rgw_get_uid_from_index(access_key, ui_key_bucket, user_id, info); + return rgw_get_user_info_from_index(access_key, ui_key_bucket, info); } static void get_buckets_obj(string& user_id, string& buckets_obj_id) diff --git a/src/rgw/rgw_user.h b/src/rgw/rgw_user.h index 39216207da2..9269407fb65 100644 --- a/src/rgw/rgw_user.h +++ b/src/rgw/rgw_user.h @@ -31,11 +31,6 @@ struct RGWUID WRITE_CLASS_ENCODER(RGWUID) /** - * Get the info for a user out of storage. - * Returns: 0 on success, -ERR# on failure - */ -extern int rgw_get_user_info(string user_id, RGWUserInfo& info); -/** * Get the anonymous (ie, unauthenticated) user info. */ extern void rgw_get_anon_user(RGWUserInfo& info); @@ -45,20 +40,25 @@ extern void rgw_get_anon_user(RGWUserInfo& info); */ extern int rgw_store_user_info(RGWUserInfo& info); /** - * Given an email, finds the user_id associated with it. + * 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(string& user_id, RGWUserInfo& info); +/** + * Given an openstack username, finds the user info associated with it. * returns: 0 on success, -ERR# on failure (including nonexistence) */ -extern int rgw_get_uid_by_email(string& email, string& user_id, RGWUserInfo& info); +extern int rgw_get_user_info_by_email(string& email, RGWUserInfo& info); /** - * Given an openstack username, finds the user_id associated with it. + * Given an openstack username, finds the user info associated with it. * returns: 0 on success, -ERR# on failure (including nonexistence) */ -extern int rgw_get_uid_by_openstack(string& openstack_name, string& user_id, RGWUserInfo& info); +extern int rgw_get_user_info_by_openstack(string& openstack_name, RGWUserInfo& info); /** - * Given an access key, finds the user_id associated with it. + * Given an access key, finds the user info associated with it. * returns: 0 on success, -ERR# on failure (including nonexistence) */ -extern int rgw_get_uid_by_access_key(string& access_key, string& user_id, RGWUserInfo& info); +extern int rgw_get_user_info_by_access_key(string& access_key, RGWUserInfo& info); /** * Given an RGWUserInfo, deletes the user and its bucket ACLs. */ |