summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorStefan Eissing <icing@apache.org>2017-08-08 13:50:20 +0000
committerStefan Eissing <icing@apache.org>2017-08-08 13:50:20 +0000
commit4ee5a66bd6a1993eb1d02a89aada556734c52bda (patch)
tree956c2859de442cc037d34081c111a2e38aea48fb
parent266f140fa876890e51b7e0aba37cd66b4173e178 (diff)
downloadhttpd-4ee5a66bd6a1993eb1d02a89aada556734c52bda.tar.gz
mod_md: v0.6.0 from github
git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/branches/trunk-md@1804424 13f79535-47bb-0310-9956-ffa450edef68
-rw-r--r--modules/md/config2.m44
-rw-r--r--modules/md/md.h1
-rw-r--r--modules/md/md_json.c16
-rw-r--r--modules/md/md_store_fs.c53
-rw-r--r--modules/md/md_version.h4
-rw-r--r--modules/md/mod_md.c6
-rw-r--r--modules/md/mod_md_config.c (renamed from modules/md/md_config.c)5
-rw-r--r--modules/md/mod_md_config.h (renamed from modules/md/md_config.h)0
-rw-r--r--modules/md/mod_md_os.c (renamed from modules/md/md_os.c)2
-rw-r--r--modules/md/mod_md_os.h (renamed from modules/md/md_os.h)0
-rw-r--r--modules/md/mod_md_private.h23
11 files changed, 91 insertions, 23 deletions
diff --git a/modules/md/config2.m4 b/modules/md/config2.m4
index 70edaf843a..034819ad7c 100644
--- a/modules/md/config2.m4
+++ b/modules/md/config2.m4
@@ -245,8 +245,8 @@ APACHE_MODPATH_INIT(md)
dnl # list of module object files
md_objs="dnl
mod_md.lo dnl
-md_config.lo dnl
-md_os.lo dnl
+mod_md_config.lo dnl
+mod_md_os.lo dnl
"
dnl # hook module into the Autoconf mechanism (--enable-md)
diff --git a/modules/md/md.h b/modules/md/md.h
index 23b7543a78..35bab07fdc 100644
--- a/modules/md/md.h
+++ b/modules/md/md.h
@@ -114,6 +114,7 @@ struct md_t {
#define MD_KEY_RESOURCE "resource"
#define MD_KEY_STATE "state"
#define MD_KEY_STATUS "status"
+#define MD_KEY_STORE "store"
#define MD_KEY_TOKEN "token"
#define MD_KEY_TYPE "type"
#define MD_KEY_URL "url"
diff --git a/modules/md/md_json.c b/modules/md/md_json.c
index fc7b13f8de..6feafa6d26 100644
--- a/modules/md/md_json.c
+++ b/modules/md/md_json.c
@@ -750,6 +750,16 @@ typedef struct {
apr_file_t *f;
} j_write_ctx;
+/* Convert from md_json_fmt_t to the Jansson json_dumpX flags. */
+static size_t fmt_to_flags(md_json_fmt_t fmt)
+{
+ /* NOTE: JSON_PRESERVE_ORDER is off by default before Jansson 2.8. It
+ * doesn't have any semantic effect on the protocol, but it does let the
+ * md_json_writeX unit tests run deterministically. */
+ return JSON_PRESERVE_ORDER |
+ ((fmt == MD_JSON_FMT_COMPACT) ? JSON_COMPACT : JSON_INDENT(2));
+}
+
static int dump_cb(const char *buffer, size_t len, void *baton)
{
apr_bucket_brigade *bb = baton;
@@ -761,8 +771,7 @@ static int dump_cb(const char *buffer, size_t len, void *baton)
apr_status_t md_json_writeb(md_json_t *json, md_json_fmt_t fmt, apr_bucket_brigade *bb)
{
- size_t flags = (fmt == MD_JSON_FMT_COMPACT)? JSON_COMPACT : JSON_INDENT(2);
- int rv = json_dump_callback(json->j, dump_cb, bb, flags);
+ int rv = json_dump_callback(json->j, dump_cb, bb, fmt_to_flags(fmt));
return rv? APR_EGENERAL : APR_SUCCESS;
}
@@ -778,12 +787,11 @@ static int chunk_cb(const char *buffer, size_t len, void *baton)
const char *md_json_writep(md_json_t *json, apr_pool_t *p, md_json_fmt_t fmt)
{
- size_t flags = (fmt == MD_JSON_FMT_COMPACT)? JSON_COMPACT : JSON_INDENT(2);
apr_array_header_t *chunks;
int rv;
chunks = apr_array_make(p, 10, sizeof(char *));
- rv = json_dump_callback(json->j, chunk_cb, chunks, flags);
+ rv = json_dump_callback(json->j, chunk_cb, chunks, fmt_to_flags(fmt));
if (rv) {
md_log_perror(MD_LOG_MARK, MD_LOG_ERR, 0, p,
diff --git a/modules/md/md_store_fs.c b/modules/md/md_store_fs.c
index f456b8fc10..09a4eb2835 100644
--- a/modules/md/md_store_fs.c
+++ b/modules/md/md_store_fs.c
@@ -37,6 +37,8 @@
/**************************************************************************************************/
/* file system based implementation of md_store_t */
+#define MD_STORE_VERSION 1.0
+
typedef struct {
apr_fileperms_t dir;
apr_fileperms_t file;
@@ -99,6 +101,7 @@ static apr_status_t init_store_file(md_store_fs_t *s_fs, const char *fname,
int i;
md_json_sets(MOD_MD_VERSION, json, MD_KEY_VERSION, NULL);
+ md_json_setn(MD_STORE_VERSION, json, MD_KEY_STORE, MD_KEY_VERSION, NULL);
/*if (APR_SUCCESS != (rv = md_rand_bytes(key, sizeof(key), p))) {
return rv;
@@ -128,18 +131,21 @@ static apr_status_t read_store_file(md_store_fs_t *s_fs, const char *fname,
md_json_t *json;
const char *s, *key64;
apr_status_t rv;
+ double store_version;
if (APR_SUCCESS == (rv = md_json_readf(&json, p, fname))) {
- s = md_json_gets(json, MD_KEY_VERSION, NULL);
- if (!s) {
- md_log_perror(MD_LOG_MARK, MD_LOG_ERR, 0, p, "missing key: %s", MD_KEY_VERSION);
- return APR_EINVAL;
+ store_version = md_json_getn(json, MD_KEY_STORE, MD_KEY_VERSION, NULL);
+ if (store_version <= 0.0) {
+ /* ok, an old one, compatible to 1.0 */
+ store_version = 1.0;
}
- if (strcmp(MOD_MD_VERSION, s) < 0) {
+ if (store_version > MD_STORE_VERSION) {
md_log_perror(MD_LOG_MARK, MD_LOG_ERR, 0, p, "version too new: %s", s);
return APR_EINVAL;
}
- /* TODO: need to migrate store? */
+ else if (store_version > MD_STORE_VERSION) {
+ /* migrate future store version changes */
+ }
key64 = md_json_dups(p, json, MD_KEY_KEY, NULL);
if (!key64) {
@@ -668,7 +674,26 @@ static apr_status_t pfs_move(void *baton, apr_pool_t *p, apr_pool_t *ptemp, va_l
rv = md_util_path_merge(&arch_dir, ptemp, dir, name, NULL);
if (APR_SUCCESS != rv) goto out;
- while (1) {
+#ifdef WIN32
+ /* WIN32 and handling of files/dirs. What can one say? */
+
+ while (n < 1000) {
+ narch_dir = apr_psprintf(ptemp, "%s.%d", arch_dir, n);
+ rv = md_util_is_dir(narch_dir, ptemp);
+ if (APR_STATUS_IS_ENOENT(rv)) {
+ md_log_perror(MD_LOG_MARK, MD_LOG_DEBUG, rv, ptemp, "using archive dir: %s",
+ narch_dir);
+ break;
+ }
+ else {
+ ++n;
+ narch_dir = NULL;
+ }
+ }
+
+#else /* ifdef WIN32 */
+
+ while (n < 1000) {
narch_dir = apr_psprintf(ptemp, "%s.%d", arch_dir, n);
rv = apr_dir_make(narch_dir, MD_FPROT_D_UONLY, ptemp);
if (APR_SUCCESS == rv) {
@@ -678,13 +703,25 @@ static apr_status_t pfs_move(void *baton, apr_pool_t *p, apr_pool_t *ptemp, va_l
}
else if (APR_EEXIST == rv) {
++n;
+ narch_dir = NULL;
}
else {
md_log_perror(MD_LOG_MARK, MD_LOG_ERR, rv, ptemp, "creating archive dir: %s",
narch_dir);
goto out;
}
- }
+ }
+
+#endif /* ifdef WIN32 (else part) */
+
+ if (!narch_dir) {
+ md_log_perror(MD_LOG_MARK, MD_LOG_ERR, rv, ptemp, "ran out of numbers less than 1000 "
+ "while looking for an available one in %s to archive the data "
+ "from %s. Either something is generally wrong or you need to "
+ "clean up some of those directories.", arch_dir, from_dir);
+ rv = APR_EGENERAL;
+ goto out;
+ }
if (APR_SUCCESS != (rv = apr_file_rename(to_dir, narch_dir, ptemp))) {
md_log_perror(MD_LOG_MARK, MD_LOG_ERR, rv, ptemp, "rename from %s to %s",
diff --git a/modules/md/md_version.h b/modules/md/md_version.h
index 60afe0f809..405734c2e9 100644
--- a/modules/md/md_version.h
+++ b/modules/md/md_version.h
@@ -26,7 +26,7 @@
* @macro
* Version number of the md module as c string
*/
-#define MOD_MD_VERSION "0.5.0-git"
+#define MOD_MD_VERSION "0.6.0"
/**
* @macro
@@ -34,7 +34,7 @@
* release. This is a 24 bit number with 8 bits for major number, 8 bits
* for minor and 8 bits for patch. Version 1.2.3 becomes 0x010203.
*/
-#define MOD_MD_VERSION_NUM 0x000500
+#define MOD_MD_VERSION_NUM 0x000600
#define MD_EXPERIMENTAL 1
#define MD_ACME_DEF_URL "https://acme-staging.api.letsencrypt.org/directory"
diff --git a/modules/md/mod_md.c b/modules/md/mod_md.c
index 691f2fcdea..caee79261f 100644
--- a/modules/md/mod_md.c
+++ b/modules/md/mod_md.c
@@ -26,8 +26,6 @@
#include <ap_listen.h>
#include "md.h"
-#include "mod_md.h"
-#include "md_config.h"
#include "md_curl.h"
#include "md_crypt.h"
#include "md_http.h"
@@ -40,7 +38,9 @@
#include "md_acme.h"
#include "md_acme_authz.h"
-#include "md_os.h"
+#include "mod_md.h"
+#include "mod_md_config.h"
+#include "mod_md_os.h"
#include "mod_watchdog.h"
static void md_hooks(apr_pool_t *pool);
diff --git a/modules/md/md_config.c b/modules/md/mod_md_config.c
index 5a31255372..c5c3d7d7ca 100644
--- a/modules/md/md_config.c
+++ b/modules/md/mod_md_config.c
@@ -25,11 +25,10 @@
#include <http_vhost.h>
#include "md.h"
-#include "md_config.h"
#include "md_util.h"
+#include "mod_md_private.h"
+#include "mod_md_config.h"
-extern module AP_MODULE_DECLARE_DATA md_module;
-APLOG_USE_MODULE(md);
#define DEF_VAL (-1)
diff --git a/modules/md/md_config.h b/modules/md/mod_md_config.h
index 3568f7c6ac..3568f7c6ac 100644
--- a/modules/md/md_config.h
+++ b/modules/md/mod_md_config.h
diff --git a/modules/md/md_os.c b/modules/md/mod_md_os.c
index 3379acbc2a..8e9896b53f 100644
--- a/modules/md/md_os.c
+++ b/modules/md/mod_md_os.c
@@ -32,7 +32,7 @@
#endif
#include "md_util.h"
-#include "md_os.h"
+#include "mod_md_os.h"
apr_status_t md_try_chown(const char *fname, int uid, int gid, apr_pool_t *p)
{
diff --git a/modules/md/md_os.h b/modules/md/mod_md_os.h
index 9f5c2b6e8f..9f5c2b6e8f 100644
--- a/modules/md/md_os.h
+++ b/modules/md/mod_md_os.h
diff --git a/modules/md/mod_md_private.h b/modules/md/mod_md_private.h
new file mode 100644
index 0000000000..d4a4a76d02
--- /dev/null
+++ b/modules/md/mod_md_private.h
@@ -0,0 +1,23 @@
+/* Copyright 2015 greenbytes GmbH (https://www.greenbytes.de)
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef mod_md_md_private_h
+#define mod_md_md_private_h
+
+extern module AP_MODULE_DECLARE_DATA md_module;
+
+APLOG_USE_MODULE(md);
+
+#endif