Apache HTTPD
Classes | Macros | Functions | Variables
md_store.c File Reference
#include <assert.h>
#include <stddef.h>
#include <stdio.h>
#include <stdlib.h>
#include <apr_lib.h>
#include <apr_file_info.h>
#include <apr_file_io.h>
#include <apr_fnmatch.h>
#include <apr_hash.h>
#include <apr_strings.h>
#include "md.h"
#include "md_crypt.h"
#include "md_log.h"
#include "md_json.h"
#include "md_store.h"
#include "md_util.h"

Go to the source code of this file.

Classes

struct  md_group_ctx
 
struct  md_load_ctx
 
struct  inspect_md_ctx
 

Macros

#define ASPECT_MD   "md.json"
 
#define ASPECT_CERT   "cert.pem"
 
#define ASPECT_PKEY   "key.pem"
 
#define ASPECT_CHAIN   "chain.pem"
 
#define GNAME_ACCOUNTS
 
#define GNAME_CHALLENGES
 
#define GNAME_DOMAINS
 
#define GNAME_STAGING
 
#define GNAME_ARCHIVE
 

Functions

const charmd_store_group_name (unsigned int group)
 
apr_status_t md_store_load (md_store_t *store, md_store_group_t group, const char *name, const char *aspect, md_store_vtype_t vtype, void **pdata, apr_pool_t *p)
 
apr_status_t md_store_save (md_store_t *store, apr_pool_t *p, md_store_group_t group, const char *name, const char *aspect, md_store_vtype_t vtype, void *data, int create)
 
apr_status_t md_store_remove (md_store_t *store, md_store_group_t group, const char *name, const char *aspect, apr_pool_t *p, int force)
 
apr_status_t md_store_purge (md_store_t *store, apr_pool_t *p, md_store_group_t group, const char *name)
 
apr_status_t md_store_iter (md_store_inspect *inspect, void *baton, md_store_t *store, apr_pool_t *p, md_store_group_t group, const char *pattern, const char *aspect, md_store_vtype_t vtype)
 
apr_status_t md_store_load_json (md_store_t *store, md_store_group_t group, const char *name, const char *aspect, struct md_json_t **pdata, apr_pool_t *p)
 
apr_status_t md_store_save_json (md_store_t *store, apr_pool_t *p, md_store_group_t group, const char *name, const char *aspect, struct md_json_t *data, int create)
 
apr_status_t md_store_move (md_store_t *store, apr_pool_t *p, md_store_group_t from, md_store_group_t to, const char *name, int archive)
 
apr_status_t md_store_get_fname (const char **pfname, md_store_t *store, md_store_group_t group, const char *name, const char *aspect, apr_pool_t *p)
 
int md_store_is_newer (md_store_t *store, md_store_group_t group1, md_store_group_t group2, const char *name, const char *aspect, apr_pool_t *p)
 
apr_time_t md_store_get_modified (md_store_t *store, md_store_group_t group, const char *name, const char *aspect, apr_pool_t *p)
 
apr_status_t md_store_iter_names (md_store_inspect *inspect, void *baton, md_store_t *store, apr_pool_t *p, md_store_group_t group, const char *pattern)
 
apr_status_t md_store_remove_not_modified_since (md_store_t *store, apr_pool_t *p, apr_time_t modified, md_store_group_t group, const char *name, const char *aspect)
 
apr_status_t md_store_rename (md_store_t *store, apr_pool_t *p, md_store_group_t group, const char *name, const char *to)
 
apr_status_t md_load (md_store_t *store, md_store_group_t group, const char *name, md_t **pmd, apr_pool_t *p)
 
static apr_status_t p_save (void *baton, apr_pool_t *p, apr_pool_t *ptemp, va_list ap)
 
apr_status_t md_save (md_store_t *store, apr_pool_t *p, md_store_group_t group, md_t *md, int create)
 
static apr_status_t p_remove (void *baton, apr_pool_t *p, apr_pool_t *ptemp, va_list ap)
 
apr_status_t md_remove (md_store_t *store, apr_pool_t *p, md_store_group_t group, const char *name, int force)
 
int md_is_newer (md_store_t *store, md_store_group_t group1, md_store_group_t group2, const char *name, apr_pool_t *p)
 
static const charpk_filename (const char *keyname, const char *base, apr_pool_t *p)
 
const charmd_pkey_filename (md_pkey_spec_t *spec, apr_pool_t *p)
 
const charmd_chain_filename (md_pkey_spec_t *spec, apr_pool_t *p)
 
apr_status_t md_pkey_load (md_store_t *store, md_store_group_t group, const char *name, md_pkey_spec_t *spec, md_pkey_t **ppkey, apr_pool_t *p)
 
apr_status_t md_pkey_save (md_store_t *store, apr_pool_t *p, md_store_group_t group, const char *name, md_pkey_spec_t *spec, struct md_pkey_t *pkey, int create)
 
apr_status_t md_pubcert_load (md_store_t *store, md_store_group_t group, const char *name, md_pkey_spec_t *spec, struct apr_array_header_t **ppubcert, apr_pool_t *p)
 
apr_status_t md_pubcert_save (md_store_t *store, apr_pool_t *p, md_store_group_t group, const char *name, md_pkey_spec_t *spec, struct apr_array_header_t *pubcert, int create)
 
apr_status_t md_creds_load (md_store_t *store, md_store_group_t group, const char *name, md_pkey_spec_t *spec, md_credentials_t **pcreds, apr_pool_t *p)
 
apr_status_t md_creds_save (md_store_t *store, apr_pool_t *p, md_store_group_t group, const char *name, md_credentials_t *creds, int create)
 
static int insp_md (void *baton, const char *name, const char *aspect, md_store_vtype_t vtype, void *value, apr_pool_t *ptemp)
 
apr_status_t md_store_md_iter (md_store_md_inspect *inspect, void *baton, md_store_t *store, apr_pool_t *p, md_store_group_t group, const char *pattern)
 
apr_status_t md_store_lock_global (md_store_t *store, apr_pool_t *p, apr_time_t max_wait)
 
void md_store_unlock_global (md_store_t *store, apr_pool_t *p)
 

Variables

static const charGROUP_NAME []
 

Macro Definition Documentation

◆ ASPECT_CERT

#define ASPECT_CERT   "cert.pem"

Definition at line 40 of file md_store.c.

◆ ASPECT_CHAIN

#define ASPECT_CHAIN   "chain.pem"

Definition at line 42 of file md_store.c.

◆ ASPECT_MD

#define ASPECT_MD   "md.json"

Definition at line 39 of file md_store.c.

◆ ASPECT_PKEY

#define ASPECT_PKEY   "key.pem"

Definition at line 41 of file md_store.c.

◆ GNAME_ACCOUNTS

#define GNAME_ACCOUNTS

Definition at line 44 of file md_store.c.

◆ GNAME_ARCHIVE

#define GNAME_ARCHIVE

Definition at line 48 of file md_store.c.

◆ GNAME_CHALLENGES

#define GNAME_CHALLENGES

Definition at line 45 of file md_store.c.

◆ GNAME_DOMAINS

#define GNAME_DOMAINS

Definition at line 46 of file md_store.c.

◆ GNAME_STAGING

#define GNAME_STAGING

Definition at line 47 of file md_store.c.

Function Documentation

◆ insp_md()

static int insp_md ( void *  baton,
const char name,
const char aspect,
md_store_vtype_t  vtype,
void *  value,
apr_pool_t ptemp 
)
static

Definition at line 351 of file md_store.c.

◆ md_chain_filename()

const char * md_chain_filename ( md_pkey_spec_t spec,
apr_pool_t p 
)

Definition at line 276 of file md_store.c.

◆ md_creds_load()

apr_status_t md_creds_load ( md_store_t store,
md_store_group_t  group,
const char name,
md_pkey_spec_t spec,
md_credentials_t **  pcreds,
apr_pool_t p 
)

Definition at line 311 of file md_store.c.

◆ md_creds_save()

apr_status_t md_creds_save ( md_store_t store,
apr_pool_t p,
md_store_group_t  group,
const char name,
md_credentials_t creds,
int  create 
)

Definition at line 329 of file md_store.c.

◆ md_is_newer()

int md_is_newer ( md_store_t store,
md_store_group_t  group1,
md_store_group_t  group2,
const char name,
apr_pool_t p 
)

Definition at line 245 of file md_store.c.

◆ md_load()

apr_status_t md_load ( md_store_t store,
md_store_group_t  group,
const char name,
md_t **  pmd,
apr_pool_t p 
)

Definition at line 179 of file md_store.c.

◆ md_pkey_filename()

const char * md_pkey_filename ( md_pkey_spec_t spec,
apr_pool_t p 
)

Definition at line 271 of file md_store.c.

◆ md_pkey_load()

apr_status_t md_pkey_load ( md_store_t store,
md_store_group_t  group,
const char name,
md_pkey_spec_t spec,
md_pkey_t **  ppkey,
apr_pool_t p 
)

Definition at line 281 of file md_store.c.

◆ md_pkey_save()

apr_status_t md_pkey_save ( md_store_t store,
apr_pool_t p,
md_store_group_t  group,
const char name,
md_pkey_spec_t spec,
struct md_pkey_t pkey,
int  create 
)

Definition at line 288 of file md_store.c.

◆ md_pubcert_load()

apr_status_t md_pubcert_load ( md_store_t store,
md_store_group_t  group,
const char name,
md_pkey_spec_t spec,
struct apr_array_header_t **  ppubcert,
apr_pool_t p 
)

Definition at line 295 of file md_store.c.

◆ md_pubcert_save()

apr_status_t md_pubcert_save ( md_store_t store,
apr_pool_t p,
md_store_group_t  group,
const char name,
md_pkey_spec_t spec,
struct apr_array_header_t pubcert,
int  create 
)

Definition at line 303 of file md_store.c.

◆ md_remove()

apr_status_t md_remove ( md_store_t store,
apr_pool_t p,
md_store_group_t  group,
const char name,
int  force 
)

Definition at line 235 of file md_store.c.

◆ md_save()

apr_status_t md_save ( md_store_t store,
apr_pool_t p,
md_store_group_t  group,
md_t md,
int  create 
)

Definition at line 211 of file md_store.c.

◆ md_store_get_fname()

apr_status_t md_store_get_fname ( const char **  pfname,
md_store_t store,
md_store_group_t  group,
const char name,
const char aspect,
apr_pool_t p 
)

Get the filename of an item stored in "group/name/aspect". The item does not have to exist.

Definition at line 127 of file md_store.c.

◆ md_store_get_modified()

apr_time_t md_store_get_modified ( md_store_t store,
md_store_group_t  group,
const char name,
const char aspect,
apr_pool_t p 
)

Get the modification time of the item store under "group/name/aspect".

Returns
modification time or 0 if the item does not exist.

Definition at line 144 of file md_store.c.

◆ md_store_group_name()

const char * md_store_group_name ( unsigned int  group)

Definition at line 62 of file md_store.c.

◆ md_store_is_newer()

int md_store_is_newer ( md_store_t store,
md_store_group_t  group1,
md_store_group_t  group2,
const char name,
const char aspect,
apr_pool_t p 
)

Make a compare on the modification time of "group1/name/aspect" vs. "group2/name/aspect".

Definition at line 138 of file md_store.c.

◆ md_store_iter()

apr_status_t md_store_iter ( md_store_inspect inspect,
void *  baton,
md_store_t store,
apr_pool_t p,
md_store_group_t  group,
const char pattern,
const char aspect,
md_store_vtype_t  vtype 
)

Iterator over all existing values matching the name pattern. Patterns are evaluated using apr_fnmatch() without flags.

Definition at line 99 of file md_store.c.

◆ md_store_iter_names()

apr_status_t md_store_iter_names ( md_store_inspect inspect,
void *  baton,
md_store_t store,
apr_pool_t p,
md_store_group_t  group,
const char pattern 
)

Iterate over all names that exist in a group, e.g. there are items matching "group/pattern". The inspect function is called with the name and NULL aspect and value.

Definition at line 150 of file md_store.c.

◆ md_store_load()

apr_status_t md_store_load ( md_store_t store,
md_store_group_t  group,
const char name,
const char aspect,
md_store_vtype_t  vtype,
void **  pdata,
apr_pool_t p 
)

Load the value of type at key "group/name/aspect", allocated from pool p. Usually, the type is expected to be the same as used in saving the value. Some conversions will work, others will fail the format.

Returns
APR_ENOENT if there is no such value

Definition at line 70 of file md_store.c.

◆ md_store_load_json()

apr_status_t md_store_load_json ( md_store_t store,
md_store_group_t  group,
const char name,
const char aspect,
struct md_json_t **  pdata,
apr_pool_t p 
)

Load the JSON value at key "group/name/aspect", allocated from pool p.

Returns
APR_ENOENT if there is no such value

Definition at line 106 of file md_store.c.

◆ md_store_lock_global()

apr_status_t md_store_lock_global ( md_store_t store,
apr_pool_t p,
apr_time_t  max_wait 
)

Acquire a cooperative, global lock on store modifications.

This will only prevent other children/processes/cluster nodes from doing the same and does not protect individual store functions from being called without it.

Parameters
storethe store
pmemory pool to use
max_waitmaximum time to wait in order to acquire
Returns
APR_SUCCESS when lock was obtained

Definition at line 377 of file md_store.c.

◆ md_store_md_iter()

apr_status_t md_store_md_iter ( md_store_md_inspect inspect,
void *  baton,
md_store_t store,
apr_pool_t p,
md_store_group_t  group,
const char pattern 
)

Definition at line 364 of file md_store.c.

◆ md_store_move()

apr_status_t md_store_move ( md_store_t store,
apr_pool_t p,
md_store_group_t  from,
md_store_group_t  to,
const char name,
int  archive 
)

Move everything matching key "from/name" from one group to another. If archive != 0, move any existing "to/name" into a new "archive/new_name" location.

Definition at line 120 of file md_store.c.

◆ md_store_purge()

apr_status_t md_store_purge ( md_store_t store,
apr_pool_t p,
md_store_group_t  group,
const char name 
)

Remove everything matching key "group/name".

Definition at line 93 of file md_store.c.

◆ md_store_remove()

apr_status_t md_store_remove ( md_store_t store,
md_store_group_t  group,
const char name,
const char aspect,
apr_pool_t p,
int  force 
)

Remove the value stored at key "group/name/aspect". Unless force != 0, a missing value will cause the call to fail with APR_ENOENT.

Definition at line 86 of file md_store.c.

◆ md_store_remove_not_modified_since()

apr_status_t md_store_remove_not_modified_since ( md_store_t store,
apr_pool_t p,
apr_time_t  modified,
md_store_group_t  group,
const char name,
const char aspect 
)

Remove all items matching the name/aspect patterns that have not been modified since the given timestamp.

Definition at line 156 of file md_store.c.

◆ md_store_rename()

apr_status_t md_store_rename ( md_store_t store,
apr_pool_t p,
md_store_group_t  group,
const char name,
const char to 
)

Rename a group member.

Definition at line 165 of file md_store.c.

◆ md_store_save()

apr_status_t md_store_save ( md_store_t store,
apr_pool_t p,
md_store_group_t  group,
const char name,
const char aspect,
md_store_vtype_t  vtype,
void *  data,
int  create 
)

Save the JSON value at key "group/name/aspect". If create != 0, fail if there already is a value for this key. The provided data MUST be of the correct type.

Definition at line 78 of file md_store.c.

◆ md_store_save_json()

apr_status_t md_store_save_json ( md_store_t store,
apr_pool_t p,
md_store_group_t  group,
const char name,
const char aspect,
struct md_json_t data,
int  create 
)

Save the JSON value at key "group/name/aspect". If create != 0, fail if there already is a value for this key.

Definition at line 113 of file md_store.c.

◆ md_store_unlock_global()

void md_store_unlock_global ( md_store_t store,
apr_pool_t p 
)

Realease the global store lock. Will do nothing if there is no lock.

Definition at line 382 of file md_store.c.

◆ p_remove()

static apr_status_t p_remove ( void *  baton,
apr_pool_t p,
apr_pool_t ptemp,
va_list  ap 
)
static

Definition at line 221 of file md_store.c.

◆ p_save()

static apr_status_t p_save ( void *  baton,
apr_pool_t p,
apr_pool_t ptemp,
va_list  ap 
)
static

Definition at line 195 of file md_store.c.

◆ pk_filename()

static const char * pk_filename ( const char keyname,
const char base,
apr_pool_t p 
)
static

Definition at line 257 of file md_store.c.

Variable Documentation

◆ GROUP_NAME

const char* GROUP_NAME[]
static
Initial value:
= {
"none",
"accounts",
"challenges",
"domains",
"staging",
"archive",
"tmp",
"ocsp",
}
return NULL
Definition mod_so.c:359

Definition at line 50 of file md_store.c.