tabled: fix buckets in subdomains
PATCH 1/1 tabled: fix buckets in subdomains
Make sure that bucket names in subdomains actually work. As it turned out, we had some simple issues, like them working with bucket.pretzel.yyz.us only, some time ago, and even that bitrotted.
Signed-off-by Pete Zaitcev <[email protected]>
--- server/bucket.c | 23 +++++++++++++++++++++++ server/server.c | 22 ++++------------------ server/tabled.h | 2 +- 3 files changed, 28 insertions(+), 19 deletions(-)
server/bucket.c +23 -0
@@ -408,6 +408,29 @@ bool bucket_base(const char *uri_path, char **pbucket, char **ppath)return true; } +/* +* Match host against ourhost and return the bucket, if any. +* This used to be handled with a regexp "^\\s*(\\w+)\\.(\\w.*)$", +* but that failed due to hostnames having a dash in them. +*/ +char *bucket_host (const char *host,const char *ourhost) +{ +size_t ourhlen =strlen (ourhost); +size_t hlen =strlen (host); +size_t bucklen; + +if (ourhlen >= hlen) +return NULL ; + bucklen = hlen-ourhlen;/* at least one */ +if (strcasecmp (host + bucklen, ourhost)) +return NULL ; +if (host[--bucklen] !='.' ) +return NULL ; +if (bucklen ==0 ) +return NULL ; +return g_strndup (host, bucklen); +} +bool bucket_add (struct client *cli,const char *user,const char *bucket) {char *hdr, timestr[64 ];
server/server.c +4 -18
@@ -53,8 +53,6 @@#define PROGRAM_NAME "tabled" -#define MY_ENDPOINT "pretzel.yyz.us" -const char *argp_program_version =PACKAGE_VERSION ;enum {
@@ -103,9 +101,6 @@ struct server tabled_srv = {struct tabledb tdb;struct compiled_pat patterns[] = { - [pat_bucket_host] = - {"^\\s*(\\w+)\\.(\\w.*)$" ,0 , }, - [pat_auth] = {"^AWS (\\w+):(\\S+)" ,0 , },
@@ -805,7 +800,6 @@ bool cli_resp_xml(struct client *cli, int http_status,static bool cli_evt_http_req (struct client *cli,unsigned int events) { -int captured[16 ];struct http_req *req = &cli->req;char *host, *auth, *content_len_str;char *bucket =NULL ;
@@ -842,21 +836,13 @@ static bool cli_evt_http_req(struct client *cli, unsigned int events)return cli_err (cli, InvalidArgument);/* attempt to obtain bucket name from Host */ -if (pcre_exec (patterns[pat_bucket_host].re,NULL , - host,strlen (host),0 ,0 , captured,16 ) ==3 ) { -if ((strlen (MY_ENDPOINT ) == (captured[5 ] - captured[4 ])) && - (!memcmp (MY_ENDPOINT , host + captured[4 ], -strlen (MY_ENDPOINT )))) { - bucket =g_strndup (host + captured[2 ], - captured[3 ] - captured[2 ]); - path =g_strndup (req->uri.path, req->uri.path_len); - } - } + bucket =bucket_host (host, tabled_srv.ourhost);/* attempt to obtain bucket name from URI path */ -if (!bucket) { +if (!bucket) buck_in_path =bucket_base (req->uri.path, &bucket, &path); - } +else + path =strdup (req->uri.path);if (!path) path =strdup ("/" );
server/tabled.h +1 -1
@@ -69,7 +69,6 @@ struct client_write;struct server_socket ;enum { - pat_bucket_host, pat_auth, pat_ipv4_addr, };
@@ -257,6 +256,7 @@ extern bool bucket_list(struct client *cli, const char *user, const char *bucketextern bool bucket_del (struct client *cli,const char *user,const char *bucket);extern bool bucket_add (struct client *cli,const char *user,const char *bucket);extern bool bucket_valid (const char *bucket); +extern char *bucket_host (const char *host,const char *ourhost);extern bool bucket_base (const char *uri_path,char **pbucket,char **ppath);extern bool service_list (struct client *cli,const char *user);
Jeff Garzik
AppliedQuoted 11 lines · Pete Zaitcev
Make sure that bucket names in subdomains actually work. As it turned out, we had some simple issues, like them working with bucket.pretzel.yyz.us only, some time ago, and even that bitrotted.
Signed-off-by Pete Zaitcev<[email protected]>--- server/bucket.c | 23 +++++++++++++++++++++++ server/server.c | 22 ++++------------------ server/tabled.h | 2 +- 3 files changed, 28 insertions(+), 19 deletions(-)
applied