[PATCH] _policy is a reserved object name; reject it,...

Jim Meyering jim at meyering.net
Thu Nov 4 15:52:21 UTC 2010


I noticed that _policy wasn't listed as a reserved object name.
We might want to do something about "_providers", which
is the sole reserved bucket name.
I'll look at that separately.


>From 30cfcfe2d708e11f027b3d8f3303680ee15b8e65 Mon Sep 17 00:00:00 2001
From: Jim Meyering <meyering at redhat.com>
Date: Thu, 4 Nov 2010 16:29:09 +0100
Subject: [PATCH] _policy is a reserved object name; reject it, just like the others

* rest.c (reserved_name): Add "_policy" to the list of reserved
object names.  Alphabetize.
(reserved_attr): Alphabetize.
Mark each array and members as const and propagate that to the
sole interface, ...
(is_reserved): More const.
* t/basic: Exercise the code that rejects reserved object names.
---
 rest.c  |    6 +++---
 t/basic |   13 +++++++++++++
 2 files changed, 16 insertions(+), 3 deletions(-)

diff --git a/rest.c b/rest.c
index 43923d4..9ff3a54 100644
--- a/rest.c
+++ b/rest.c
@@ -69,8 +69,8 @@ static unsigned short		 my_port	= MY_PORT;
 const char			*program_name;
 char				*cfg_file	= NULL;

-static char *(reserved_name[]) = { "_default", "_query", "_new", NULL };
-static char *(reserved_attr[]) = { "bucket", "key", "date", "etag", "loc", NULL };
+static const char *const (reserved_name[]) = {"_default", "_new", "_policy", "_query", NULL};
+static const char *const (reserved_attr[]) = {"bucket", "date", "etag", "key", "loc", NULL};

 void
 free_ms (my_state *ms)
@@ -137,7 +137,7 @@ validate_put (struct MHD_Connection *conn)
 }

 static int
-is_reserved (const char *cand, char **resv_list)
+is_reserved (const char *cand, char const *const *resv_list)
 {
 	int	i;

diff --git a/t/basic b/t/basic
index 4f979f0..7075cf1 100644
--- a/t/basic
+++ b/t/basic
@@ -270,6 +270,19 @@ curl -d key=attr_post -d shape=round -d size=big $bucket || fail=1
 test "$(curl $bucket/attr_post/shape)" = round || fail=1
 test "$(curl $bucket/attr_post/size)" = big || fail=1

+# Ensure that an attempt to add reserved object name fails.
+# FIXME: keep this list in sync with the one in rest.c:
+# grep '^static.*reserved_name' rest.c
+for obj_name in _default _new _policy _query; do
+  echo reserved-obj-name | curl -f -T - $bucket/$obj_name 2> bad_oname.err
+  # _query evokes 404.  all others evoke 403
+  case $obj_name in
+    _query) exp=404;;
+    *) exp=403;;
+  esac
+  grep " $exp\$" bad_oname.err || fail=1
+done
+
 # Ensure that an attempt to add each reserved attribute fails.
 # FIXME: keep this list in sync with the one in rest.c:
 # grep '^static.*reserved_attr' rest.c
--
1.7.3.2.193.g78bbb


More information about the iwhd-devel mailing list