return -EINVAL;
}
-int gen_rand_base64(char *dest, int size) /* size should be the required string size + 1 */
-{
- char buf[size];
- 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) {
- cerr << "cannot get random bytes: " << cpp_strerror(-ret) << std::endl;
- return -1;
- }
-
- ret = ceph_armor(tmp_dest, &tmp_dest[sizeof(tmp_dest)],
- (const char *)buf, ((const char *)buf) + ((size - 1) * 3 + 4 - 1) / 4);
- if (ret < 0) {
- cerr << "ceph_armor failed" << std::endl;
- return -1;
- }
- tmp_dest[ret] = '\0';
- memcpy(dest, tmp_dest, size);
- dest[size] = '\0';
-
- return 0;
-}
-
-static const char alphanum_table[]="0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ";
-
-int gen_rand_alphanumeric(char *dest, int size) /* size should be the required string size + 1 */
-{
- int ret = get_random_bytes(dest, size);
- if (ret < 0) {
- cerr << "cannot get random bytes: " << cpp_strerror(-ret) << std::endl;
- return -1;
- }
-
- int i;
- for (i=0; i<size - 1; i++) {
- int pos = (unsigned)dest[i];
- dest[i] = alphanum_table[pos % (sizeof(alphanum_table) - 1)];
- }
- dest[i] = '\0';
-
- return 0;
-}
-
string escape_str(string& src, char c)
{
int pos = 0;
RGWUserInfo duplicate_check;
string duplicate_check_id;
do {
- ret = gen_rand_alphanumeric(public_id_buf, sizeof(public_id_buf));
+ ret = gen_rand_alphanumeric_upper(public_id_buf, sizeof(public_id_buf));
if (ret < 0) {
cerr << "aborting" << std::endl;
exit(1);
#include "rgw_acl.h"
#include "common/ceph_crypto.h"
+#include "common/armor.h"
+#include "common/errno.h"
+#include "auth/Crypto.h"
using namespace ceph::crypto;
RGW_LOG(15) << "hmac=" << hex_str << dendl;
}
+int gen_rand_base64(char *dest, int size) /* size should be the required string size + 1 */
+{
+ char buf[size];
+ 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) {
+ cerr << "cannot get random bytes: " << cpp_strerror(-ret) << std::endl;
+ return -1;
+ }
+
+ ret = ceph_armor(tmp_dest, &tmp_dest[sizeof(tmp_dest)],
+ (const char *)buf, ((const char *)buf) + ((size - 1) * 3 + 4 - 1) / 4);
+ if (ret < 0) {
+ cerr << "ceph_armor failed" << std::endl;
+ return -1;
+ }
+ tmp_dest[ret] = '\0';
+ memcpy(dest, tmp_dest, size);
+ dest[size] = '\0';
+
+ return 0;
+}
+
+static const char alphanum_upper_table[]="0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ";
+
+int gen_rand_alphanumeric_upper(char *dest, int size) /* size should be the required string size + 1 */
+{
+ int ret = get_random_bytes(dest, size);
+ if (ret < 0) {
+ cerr << "cannot get random bytes: " << cpp_strerror(-ret) << std::endl;
+ return -1;
+ }
+
+ int i;
+ for (i=0; i<size - 1; i++) {
+ int pos = (unsigned)dest[i];
+ dest[i] = alphanum_upper_table[pos % (sizeof(alphanum_upper_table) - 1)];
+ }
+ dest[i] = '\0';
+
+ return 0;
+}
+
+
+// this is basically a modified base64 charset, url friendly
+static const char alphanum_table[]="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_";
+
+int gen_rand_alphanumeric(char *dest, int size) /* size should be the required string size + 1 */
+{
+ int ret = get_random_bytes(dest, size);
+ if (ret < 0) {
+ cerr << "cannot get random bytes: " << cpp_strerror(-ret) << std::endl;
+ return -1;
+ }
+
+ int i;
+ for (i=0; i<size - 1; i++) {
+ int pos = (unsigned)dest[i];
+ dest[i] = alphanum_table[pos & 63];
+ }
+ dest[i] = '\0';
+
+ return 0;
+}
+
int NameVal::parse()
{
int delim_pos = str.find('=');
typedef void *RGWAccessHandle;
+ /* size should be the required string size + 1 */
+extern int gen_rand_base64(char *dest, int size);
+extern int gen_rand_alphanumeric(char *dest, int size);
+extern int gen_rand_alphanumeric_upper(char *dest, int size);
+
/** Store error returns for output at a different point in the program */
struct rgw_err {
rgw_err();
get_request_metadata(s, attrs);
- upload_id="blabla";
+ do {
+ char buf[33];
+ gen_rand_alphanumeric(buf, sizeof(buf) - 1);
+ upload_id = buf;
- ret = rgwstore->put_obj_meta(s->user.user_id, s->bucket_str, s->object_str, NULL, attrs, true);
+ string tmp_obj_name = s->object_str;
+ tmp_obj_name.append(".");
+ tmp_obj_name.append(upload_id);
+
+ ret = rgwstore->put_obj_meta(s->user.user_id, s->bucket_str, tmp_obj_name, NULL, attrs, true);
+ } while (ret == -EEXIST);
done:
send_response();
}