char tmp_dest[size + 4]; /* so that there's space for the extra '=' characters, and some */
int ret;
- ret = get_random_bytes(buf, sizeof(buf));
- if (ret < 0) {
- lderr(cct) << "cannot get random bytes: " << cpp_strerror(-ret) << dendl;
- return ret;
- }
+ cct->random()->get_bytes(buf, sizeof(buf));
ret = ceph_armor(tmp_dest, &tmp_dest[sizeof(tmp_dest)],
(const char *)buf, ((const char *)buf) + ((size - 1) * 3 + 4 - 1) / 4);
static const char alphanum_upper_table[]="0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ";
-int gen_rand_alphanumeric_upper(CephContext *cct, char *dest, int size) /* size should be the required string size + 1 */
+void gen_rand_alphanumeric_upper(CephContext *cct, char *dest, int size) /* size should be the required string size + 1 */
{
- int ret = get_random_bytes(dest, size);
- if (ret < 0) {
- lderr(cct) << "cannot get random bytes: " << cpp_strerror(-ret) << dendl;
- return ret;
- }
+ cct->random()->get_bytes(dest, size);
int i;
for (i=0; i<size - 1; i++) {
dest[i] = alphanum_upper_table[pos % (sizeof(alphanum_upper_table) - 1)];
}
dest[i] = '\0';
-
- return 0;
}
static const char alphanum_lower_table[]="0123456789abcdefghijklmnopqrstuvwxyz";
-int gen_rand_alphanumeric_lower(CephContext *cct, char *dest, int size) /* size should be the required string size + 1 */
+void gen_rand_alphanumeric_lower(CephContext *cct, char *dest, int size) /* size should be the required string size + 1 */
{
- int ret = get_random_bytes(dest, size);
- if (ret < 0) {
- lderr(cct) << "cannot get random bytes: " << cpp_strerror(-ret) << dendl;
- return ret;
- }
+ cct->random()->get_bytes(dest, size);
int i;
for (i=0; i<size - 1; i++) {
dest[i] = alphanum_lower_table[pos % (sizeof(alphanum_lower_table) - 1)];
}
dest[i] = '\0';
-
- return 0;
}
-int gen_rand_alphanumeric_lower(CephContext *cct, string *str, int length)
+void gen_rand_alphanumeric_lower(CephContext *cct, string *str, int length)
{
char buf[length + 1];
- int ret = gen_rand_alphanumeric_lower(cct, buf, sizeof(buf));
- if (ret < 0) {
- return ret;
- }
+ gen_rand_alphanumeric_lower(cct, buf, sizeof(buf));
*str = buf;
- return 0;
}
// this is basically a modified base64 charset, url friendly
static const char alphanum_table[]="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_";
-int gen_rand_alphanumeric(CephContext *cct, char *dest, int size) /* size should be the required string size + 1 */
+void gen_rand_alphanumeric(CephContext *cct, char *dest, int size) /* size should be the required string size + 1 */
{
- int ret = get_random_bytes(dest, size);
- if (ret < 0) {
- lderr(cct) << "cannot get random bytes: " << cpp_strerror(-ret) << dendl;
- return ret;
- }
+ cct->random()->get_bytes(dest, size);
int i;
for (i=0; i<size - 1; i++) {
dest[i] = alphanum_table[pos & 63];
}
dest[i] = '\0';
-
- return 0;
}
static const char alphanum_no_underscore_table[]="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-.";
-int gen_rand_alphanumeric_no_underscore(CephContext *cct, char *dest, int size) /* size should be the required string size + 1 */
+void gen_rand_alphanumeric_no_underscore(CephContext *cct, char *dest, int size) /* size should be the required string size + 1 */
{
- int ret = get_random_bytes(dest, size);
- if (ret < 0) {
- lderr(cct) << "cannot get random bytes: " << cpp_strerror(-ret) << dendl;
- return ret;
- }
+ cct->random()->get_bytes(dest, size);
int i;
for (i=0; i<size - 1; i++) {
dest[i] = alphanum_no_underscore_table[pos & 63];
}
dest[i] = '\0';
-
- return 0;
}
static const char alphanum_plain_table[]="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
-int gen_rand_alphanumeric_plain(CephContext *cct, char *dest, int size) /* size should be the required string size + 1 */
+void gen_rand_alphanumeric_plain(CephContext *cct, char *dest, int size) /* size should be the required string size + 1 */
{
- int ret = get_random_bytes(dest, size);
- if (ret < 0) {
- lderr(cct) << "cannot get random bytes: " << cpp_strerror(-ret) << dendl;
- return ret;
- }
+ cct->random()->get_bytes(dest, size);
int i;
for (i=0; i<size - 1; i++) {
dest[i] = alphanum_plain_table[pos % (sizeof(alphanum_plain_table) - 1)];
}
dest[i] = '\0';
-
- return 0;
}
int NameVal::parse()
/* size should be the required string size + 1 */
-extern int gen_rand_base64(CephContext *cct, char *dest, int size);
-extern int gen_rand_alphanumeric(CephContext *cct, char *dest, int size);
-extern int gen_rand_alphanumeric_lower(CephContext *cct, char *dest, int size);
-extern int gen_rand_alphanumeric_upper(CephContext *cct, char *dest, int size);
-extern int gen_rand_alphanumeric_no_underscore(CephContext *cct, char *dest, int size);
-extern int gen_rand_alphanumeric_plain(CephContext *cct, char *dest, int size);
-
-extern int gen_rand_alphanumeric_lower(CephContext *cct, string *str, int length);
+int gen_rand_base64(CephContext *cct, char *dest, int size);
+void gen_rand_alphanumeric(CephContext *cct, char *dest, int size);
+void gen_rand_alphanumeric_lower(CephContext *cct, char *dest, int size);
+void gen_rand_alphanumeric_upper(CephContext *cct, char *dest, int size);
+void gen_rand_alphanumeric_no_underscore(CephContext *cct, char *dest, int size);
+void gen_rand_alphanumeric_plain(CephContext *cct, char *dest, int size);
+void gen_rand_alphanumeric_lower(CephContext *cct, string *str, int length);
enum RGWIntentEvent {
DEL_OBJ = 0,
std::string create_random_key_selector(CephContext * const cct) {
char random[AES_256_KEYSIZE];
- if (get_random_bytes(&random[0], sizeof(random)) != 0) {
- ldout(cct, 0) << "ERROR: cannot get_random_bytes. " << dendl;
- for (char& v:random) v=rand();
- }
+ cct->random()->get_bytes(&random[0], sizeof(random));
return std::string(random, sizeof(random));
}
if (!has_tag) {
/* obj tag */
string obj_tag;
- int ret = gen_rand_alphanumeric_lower(cct, &obj_tag, 32);
- if (ret < 0) {
- ldout(cct, 0) << "ERROR: gen_rand_alphanumeric_lower() returned ret=" << ret << dendl;
- return ret;
- }
+ gen_rand_alphanumeric_lower(cct, &obj_tag, 32);
+
bufferlist bl;
bl.append(obj_tag.c_str(), obj_tag.size());
op.setxattr(RGW_ATTR_ID_TAG, bl);
/* olh tag */
string olh_tag;
- ret = gen_rand_alphanumeric_lower(cct, &olh_tag, 32);
- if (ret < 0) {
- ldout(cct, 0) << "ERROR: gen_rand_alphanumeric_lower() returned ret=" << ret << dendl;
- return ret;
- }
+ gen_rand_alphanumeric_lower(cct, &olh_tag, 32);
+
bufferlist olh_bl;
olh_bl.append(olh_tag.c_str(), olh_tag.size());
op.setxattr(RGW_ATTR_OLH_ID_TAG, olh_bl);
*op_tag = buf;
string s;
- int ret = gen_rand_alphanumeric_lower(cct, &s, OLH_PENDING_TAG_LEN - op_tag->size());
- if (ret < 0) {
- ldout(cct, 0) << "ERROR: gen_rand_alphanumeric_lower() returned ret=" << ret << dendl;
- return ret;
- }
+ gen_rand_alphanumeric_lower(cct, &s, OLH_PENDING_TAG_LEN - op_tag->size());
+
op_tag->append(s);
string attr_name = RGW_ATTR_OLH_PENDING_PREFIX;
op.setxattr(attr_name.c_str(), bl);
- ret = obj_operate(bucket_info, olh_obj, &op);
+ int ret = obj_operate(bucket_info, olh_obj, &op);
if (ret < 0) {
return ret;
}
RGWAccessKey new_key;
RGWUserInfo duplicate_check;
- int ret = 0;
int key_type = op_state.get_key_type();
bool gen_access = op_state.will_gen_access();
bool gen_secret = op_state.will_gen_secret();
key = op_state.get_secret_key();
} else {
char secret_key_buf[SECRET_KEY_LEN + 1];
-
- ret = gen_rand_alphanumeric_plain(g_ceph_context, secret_key_buf, sizeof(secret_key_buf));
- if (ret < 0) {
- set_err_msg(err_msg, "unable to generate secret key");
- return ret;
- }
-
+ gen_rand_alphanumeric_plain(g_ceph_context, secret_key_buf, sizeof(secret_key_buf));
key = secret_key_buf;
}
do {
int id_buf_size = sizeof(public_id_buf);
- ret = gen_rand_alphanumeric_upper(g_ceph_context,
- public_id_buf, id_buf_size);
-
- if (ret < 0) {
- set_err_msg(err_msg, "unable to generate access key");
- return ret;
- }
-
+ gen_rand_alphanumeric_upper(g_ceph_context, public_id_buf, id_buf_size);
id = public_id_buf;
if (!validate_access_key(id))
continue;
if (op_state.will_gen_secret()) {
char secret_key_buf[SECRET_KEY_LEN + 1];
-
- int ret;
int key_buf_size = sizeof(secret_key_buf);
- ret = gen_rand_alphanumeric_plain(g_ceph_context, secret_key_buf, key_buf_size);
- if (ret < 0) {
- set_err_msg(err_msg, "unable to generate secret key");
- return ret;
- }
-
+ gen_rand_alphanumeric_plain(g_ceph_context, secret_key_buf, key_buf_size);
key = secret_key_buf;
}
int sub_buf_size = RAND_SUBUSER_LEN + 1;
char sub_buf[RAND_SUBUSER_LEN + 1];
- if (gen_rand_alphanumeric_upper(g_ceph_context, sub_buf, sub_buf_size) < 0)
- return "";
+ gen_rand_alphanumeric_upper(g_ceph_context, sub_buf, sub_buf_size);
rand_suffix = sub_buf;
if (rand_suffix.empty())