keep cert/key/ocsp path as strings and don't send them via imsg

This commit is contained in:
Omar Polo 2023-06-08 19:34:49 +00:00
parent 49bd46a150
commit 1c6967b33a
3 changed files with 23 additions and 16 deletions

View File

@ -73,6 +73,9 @@ config_free(void)
init_mime(&conf.mime);
TAILQ_FOREACH_SAFE(h, &hosts, vhosts, th) {
free(h->cert_path);
free(h->key_path);
free(h->ocsp_path);
free(h->cert);
free(h->key);
free(h->ocsp);
@ -255,10 +258,17 @@ config_send(struct conf *conf, struct fcgi *fcgi, struct vhosthead *hosts)
}
TAILQ_FOREACH(h, hosts, vhosts) {
struct vhost vcopy;
memcpy(&vcopy, h, sizeof(vcopy));
vcopy.cert_path = NULL;
vcopy.key_path = NULL;
vcopy.ocsp_path = NULL;
log_debug("sending host %s", h->domain);
if (proc_compose(ps, PROC_SERVER, IMSG_RECONF_HOST,
h, sizeof(*h)) == -1)
&vcopy, sizeof(vcopy)) == -1)
return -1;
log_debug("sending certificate %s", h->cert_path);
@ -273,7 +283,7 @@ config_send(struct conf *conf, struct fcgi *fcgi, struct vhosthead *hosts)
if (config_send_file(ps, fd, IMSG_RECONF_KEY) == -1)
return -1;
if (*h->ocsp_path != '\0') {
if (h->ocsp_path != NULL) {
log_debug("sending ocsp %s", h->ocsp_path);
if ((fd = open(h->ocsp_path, O_RDONLY)) == -1)
fatal("can't open %s", h->ocsp_path);

6
gmid.h
View File

@ -167,9 +167,9 @@ struct alist {
extern TAILQ_HEAD(vhosthead, vhost) hosts;
struct vhost {
char domain[HOST_NAME_MAX + 1];
char cert_path[PATH_MAX];
char key_path[PATH_MAX];
char ocsp_path[PATH_MAX];
char *cert_path;
char *key_path;
char *ocsp_path;
uint8_t *cert;
size_t certlen;

19
parse.y
View File

@ -254,8 +254,8 @@ vhost : SERVER string {
free($2);
} '{' optnl servbody '}' {
if (*host->cert_path == '\0' ||
*host->key_path == '\0')
if (host->cert_path == NULL ||
host->key_path == NULL)
yyerror("invalid vhost definition: %s", $2);
}
| error '}' { yyerror("bad server directive"); }
@ -277,21 +277,18 @@ servopt : ALIAS string {
}
| CERT string {
ensure_absolute_path($2);
(void) strlcpy(host->cert_path, $2,
sizeof(host->cert_path));
free($2);
free(host->cert_path);
host->cert_path = $2;
}
| KEY string {
ensure_absolute_path($2);
(void) strlcpy(host->key_path, $2,
sizeof(host->key_path));
free($2);
free(host->key_path);
host->key_path = $2;
}
| OCSP string {
ensure_absolute_path($2);
(void) strlcpy(host->ocsp_path, $2,
sizeof(host->ocsp_path));
free($2);
free(host->ocsp_path);
host->ocsp_path = $2;
}
| PARAM string '=' string {
add_param($2, $4);