[Patch] tabled: fix buckets in subdomains

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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 <zaitcev@xxxxxxxxxx>

---
 server/bucket.c |   23 +++++++++++++++++++++++
 server/server.c |   22 ++++------------------
 server/tabled.h |    2 +-
 3 files changed, 28 insertions(+), 19 deletions(-)

diff --git a/server/bucket.c b/server/bucket.c
index 976d716..c13ec05 100644
--- a/server/bucket.c
+++ b/server/bucket.c
@@ -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];
diff --git a/server/server.c b/server/server.c
index d9320ec..f7ea446 100644
--- a/server/server.c
+++ b/server/server.c
@@ -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("/");
diff --git a/server/tabled.h b/server/tabled.h
index 3cb6ab3..91eb025 100644
--- a/server/tabled.h
+++ b/server/tabled.h
@@ -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 *bucket
 extern 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);
 
--
To unsubscribe from this list: send the line "unsubscribe hail-devel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html

[Index of Archives]     [Fedora Clound]     [Linux USB Devel]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]     [XFree86]

  Powered by Linux