Commit b062d92c authored by Stefan Eissing's avatar Stefan Eissing
Browse files

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
parent 84d21d1e
Loading
Loading
Loading
Loading
+2 −2
Original line number Original line Diff line number Diff line
@@ -245,8 +245,8 @@ APACHE_MODPATH_INIT(md)
dnl #  list of module object files
dnl #  list of module object files
md_objs="dnl
md_objs="dnl
mod_md.lo dnl
mod_md.lo dnl
md_config.lo dnl
mod_md_config.lo dnl
md_os.lo dnl
mod_md_os.lo dnl
"
"


dnl # hook module into the Autoconf mechanism (--enable-md)
dnl # hook module into the Autoconf mechanism (--enable-md)
+1 −0
Original line number Original line Diff line number Diff line
@@ -114,6 +114,7 @@ struct md_t {
#define MD_KEY_RESOURCE         "resource"
#define MD_KEY_RESOURCE         "resource"
#define MD_KEY_STATE            "state"
#define MD_KEY_STATE            "state"
#define MD_KEY_STATUS           "status"
#define MD_KEY_STATUS           "status"
#define MD_KEY_STORE            "store"
#define MD_KEY_TOKEN            "token"
#define MD_KEY_TOKEN            "token"
#define MD_KEY_TYPE             "type"
#define MD_KEY_TYPE             "type"
#define MD_KEY_URL              "url"
#define MD_KEY_URL              "url"
+12 −4
Original line number Original line Diff line number Diff line
@@ -750,6 +750,16 @@ typedef struct {
    apr_file_t *f;
    apr_file_t *f;
} j_write_ctx;
} 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)
static int dump_cb(const char *buffer, size_t len, void *baton)
{
{
    apr_bucket_brigade *bb = 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)
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, fmt_to_flags(fmt));
    int rv = json_dump_callback(json->j, dump_cb, bb, flags);
    return rv? APR_EGENERAL : APR_SUCCESS;
    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)
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;
    apr_array_header_t *chunks;
    int rv;
    int rv;


    chunks = apr_array_make(p, 10, sizeof(char *));
    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) {
    if (rv) {
        md_log_perror(MD_LOG_MARK, MD_LOG_ERR, 0, p,
        md_log_perror(MD_LOG_MARK, MD_LOG_ERR, 0, p,
+45 −8
Original line number Original line Diff line number Diff line
@@ -37,6 +37,8 @@
/**************************************************************************************************/
/**************************************************************************************************/
/* file system based implementation of md_store_t */
/* file system based implementation of md_store_t */


#define MD_STORE_VERSION        1.0

typedef struct {
typedef struct {
    apr_fileperms_t dir;
    apr_fileperms_t dir;
    apr_fileperms_t file;
    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;
    int i;
    
    
    md_json_sets(MOD_MD_VERSION, json, MD_KEY_VERSION, NULL);
    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))) {
    /*if (APR_SUCCESS != (rv = md_rand_bytes(key, sizeof(key), p))) {
        return rv;
        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;
    md_json_t *json;
    const char *s, *key64;
    const char *s, *key64;
    apr_status_t rv;
    apr_status_t rv;
    double store_version;
    
    
    if (APR_SUCCESS == (rv = md_json_readf(&json, p, fname))) {
    if (APR_SUCCESS == (rv = md_json_readf(&json, p, fname))) {
        s = md_json_gets(json, MD_KEY_VERSION, NULL);
        store_version = md_json_getn(json, MD_KEY_STORE, MD_KEY_VERSION, NULL);
        if (!s) {
        if (store_version <= 0.0) {
            md_log_perror(MD_LOG_MARK, MD_LOG_ERR, 0, p, "missing key: %s", MD_KEY_VERSION);
            /* ok, an old one, compatible to 1.0 */
            return APR_EINVAL;
            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);
            md_log_perror(MD_LOG_MARK, MD_LOG_ERR, 0, p, "version too new: %s", s);
            return APR_EINVAL;
            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);
        key64 = md_json_dups(p, json, MD_KEY_KEY, NULL);
        if (!key64) {
        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);
        rv = md_util_path_merge(&arch_dir, ptemp, dir, name, NULL);
        if (APR_SUCCESS != rv) goto out;
        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);
            narch_dir = apr_psprintf(ptemp, "%s.%d", arch_dir, n);
            rv = apr_dir_make(narch_dir, MD_FPROT_D_UONLY, ptemp);
            rv = apr_dir_make(narch_dir, MD_FPROT_D_UONLY, ptemp);
            if (APR_SUCCESS == rv) {
            if (APR_SUCCESS == rv) {
@@ -678,6 +703,7 @@ static apr_status_t pfs_move(void *baton, apr_pool_t *p, apr_pool_t *ptemp, va_l
            }
            }
            else if (APR_EEXIST == rv) {
            else if (APR_EEXIST == rv) {
                ++n;
                ++n;
                narch_dir = NULL;
            }
            }
            else {
            else {
                md_log_perror(MD_LOG_MARK, MD_LOG_ERR, rv, ptemp, "creating archive dir: %s", 
                md_log_perror(MD_LOG_MARK, MD_LOG_ERR, rv, ptemp, "creating archive dir: %s", 
@@ -686,6 +712,17 @@ static apr_status_t pfs_move(void *baton, apr_pool_t *p, apr_pool_t *ptemp, va_l
            }
            }
        }
        }
         
         
#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))) {
        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", 
                md_log_perror(MD_LOG_MARK, MD_LOG_ERR, rv, ptemp, "rename from %s to %s", 
                              to_dir, narch_dir);
                              to_dir, narch_dir);
+2 −2
Original line number Original line Diff line number Diff line
@@ -26,7 +26,7 @@
 * @macro
 * @macro
 * Version number of the md module as c string
 * 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
 * @macro
@@ -34,7 +34,7 @@
 * release. This is a 24 bit number with 8 bits for major number, 8 bits
 * 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.
 * 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_EXPERIMENTAL 1
#define MD_ACME_DEF_URL    "https://acme-staging.api.letsencrypt.org/directory"
#define MD_ACME_DEF_URL    "https://acme-staging.api.letsencrypt.org/directory"
Loading