mirror of https://github.com/omar-polo/gmid.git
don't have the config being a global
This commit is contained in:
parent
e45334e6ae
commit
af1dab1870
74
config.c
74
config.c
|
@ -25,28 +25,32 @@
|
||||||
#include "log.h"
|
#include "log.h"
|
||||||
#include "proc.h"
|
#include "proc.h"
|
||||||
|
|
||||||
void
|
struct conf *
|
||||||
config_init(void)
|
config_new(void)
|
||||||
{
|
{
|
||||||
memset(&conf, 0, sizeof(conf));
|
struct conf *conf;
|
||||||
|
|
||||||
TAILQ_INIT(&conf.fcgi);
|
conf = xcalloc(1, sizeof(*conf));
|
||||||
TAILQ_INIT(&conf.hosts);
|
|
||||||
|
|
||||||
conf.port = 1965;
|
TAILQ_INIT(&conf->fcgi);
|
||||||
conf.ipv6 = 0;
|
TAILQ_INIT(&conf->hosts);
|
||||||
conf.protos = TLS_PROTOCOL_TLSv1_2 | TLS_PROTOCOL_TLSv1_3;
|
|
||||||
|
|
||||||
init_mime(&conf.mime);
|
conf->port = 1965;
|
||||||
|
conf->ipv6 = 0;
|
||||||
|
conf->protos = TLS_PROTOCOL_TLSv1_2 | TLS_PROTOCOL_TLSv1_3;
|
||||||
|
|
||||||
conf.prefork = 3;
|
init_mime(&conf->mime);
|
||||||
|
|
||||||
conf.sock4 = -1;
|
conf->prefork = 3;
|
||||||
conf.sock6 = -1;
|
|
||||||
|
conf->sock4 = -1;
|
||||||
|
conf->sock6 = -1;
|
||||||
|
|
||||||
|
return conf;
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
config_free(void)
|
config_purge(struct conf *conf)
|
||||||
{
|
{
|
||||||
struct privsep *ps;
|
struct privsep *ps;
|
||||||
struct fcgi *f, *tf;
|
struct fcgi *f, *tf;
|
||||||
|
@ -56,25 +60,25 @@ config_free(void)
|
||||||
struct envlist *e, *te;
|
struct envlist *e, *te;
|
||||||
struct alist *a, *ta;
|
struct alist *a, *ta;
|
||||||
|
|
||||||
ps = conf.ps;
|
ps = conf->ps;
|
||||||
|
|
||||||
if (conf.sock4 != -1) {
|
if (conf->sock4 != -1) {
|
||||||
event_del(&conf.evsock4);
|
event_del(&conf->evsock4);
|
||||||
close(conf.sock4);
|
close(conf->sock4);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (conf.sock6 != -1) {
|
if (conf->sock6 != -1) {
|
||||||
event_del(&conf.evsock6);
|
event_del(&conf->evsock6);
|
||||||
close(conf.sock6);
|
close(conf->sock6);
|
||||||
}
|
}
|
||||||
|
|
||||||
free_mime(&conf.mime);
|
free_mime(&conf->mime);
|
||||||
TAILQ_FOREACH_SAFE(f, &conf.fcgi, fcgi, tf) {
|
TAILQ_FOREACH_SAFE(f, &conf->fcgi, fcgi, tf) {
|
||||||
TAILQ_REMOVE(&conf.fcgi, f, fcgi);
|
TAILQ_REMOVE(&conf->fcgi, f, fcgi);
|
||||||
free(f);
|
free(f);
|
||||||
}
|
}
|
||||||
|
|
||||||
TAILQ_FOREACH_SAFE(h, &conf.hosts, vhosts, th) {
|
TAILQ_FOREACH_SAFE(h, &conf->hosts, vhosts, th) {
|
||||||
free(h->cert_path);
|
free(h->cert_path);
|
||||||
free(h->key_path);
|
free(h->key_path);
|
||||||
free(h->ocsp_path);
|
free(h->ocsp_path);
|
||||||
|
@ -114,18 +118,18 @@ config_free(void)
|
||||||
free(p);
|
free(p);
|
||||||
}
|
}
|
||||||
|
|
||||||
TAILQ_REMOVE(&conf.hosts, h, vhosts);
|
TAILQ_REMOVE(&conf->hosts, h, vhosts);
|
||||||
free(h);
|
free(h);
|
||||||
}
|
}
|
||||||
|
|
||||||
memset(&conf, 0, sizeof(conf));
|
memset(conf, 0, sizeof(*conf));
|
||||||
|
|
||||||
conf.ps = ps;
|
conf->ps = ps;
|
||||||
conf.sock4 = conf.sock6 = -1;
|
conf->sock4 = conf->sock6 = -1;
|
||||||
conf.protos = TLS_PROTOCOL_TLSv1_2 | TLS_PROTOCOL_TLSv1_3;
|
conf->protos = TLS_PROTOCOL_TLSv1_2 | TLS_PROTOCOL_TLSv1_3;
|
||||||
init_mime(&conf.mime);
|
init_mime(&conf->mime);
|
||||||
TAILQ_INIT(&conf.fcgi);
|
TAILQ_INIT(&conf->fcgi);
|
||||||
TAILQ_INIT(&conf.hosts);
|
TAILQ_INIT(&conf->hosts);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int
|
static int
|
||||||
|
@ -461,7 +465,7 @@ config_recv(struct conf *conf, struct imsg *imsg)
|
||||||
|
|
||||||
switch (imsg->hdr.type) {
|
switch (imsg->hdr.type) {
|
||||||
case IMSG_RECONF_START:
|
case IMSG_RECONF_START:
|
||||||
config_free();
|
config_purge(conf);
|
||||||
h = NULL;
|
h = NULL;
|
||||||
p = NULL;
|
p = NULL;
|
||||||
break;
|
break;
|
||||||
|
@ -494,7 +498,7 @@ config_recv(struct conf *conf, struct imsg *imsg)
|
||||||
fatalx("missing socket for IMSG_RECONF_SOCK4");
|
fatalx("missing socket for IMSG_RECONF_SOCK4");
|
||||||
conf->sock4 = imsg->fd;
|
conf->sock4 = imsg->fd;
|
||||||
event_set(&conf->evsock4, conf->sock4, EV_READ|EV_PERSIST,
|
event_set(&conf->evsock4, conf->sock4, EV_READ|EV_PERSIST,
|
||||||
do_accept, NULL);
|
do_accept, conf);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case IMSG_RECONF_SOCK6:
|
case IMSG_RECONF_SOCK6:
|
||||||
|
@ -504,7 +508,7 @@ config_recv(struct conf *conf, struct imsg *imsg)
|
||||||
fatalx("missing socket for IMSG_RECONF_SOCK6");
|
fatalx("missing socket for IMSG_RECONF_SOCK6");
|
||||||
conf->sock6 = imsg->fd;
|
conf->sock6 = imsg->fd;
|
||||||
event_set(&conf->evsock6, conf->sock6, EV_READ|EV_PERSIST,
|
event_set(&conf->evsock6, conf->sock6, EV_READ|EV_PERSIST,
|
||||||
do_accept, NULL);
|
do_accept, conf);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case IMSG_RECONF_FCGI:
|
case IMSG_RECONF_FCGI:
|
||||||
|
|
22
ge.c
22
ge.c
|
@ -31,7 +31,6 @@
|
||||||
|
|
||||||
#include "log.h"
|
#include "log.h"
|
||||||
|
|
||||||
struct conf conf;
|
|
||||||
int privsep_process;
|
int privsep_process;
|
||||||
|
|
||||||
static const struct option opts[] = {
|
static const struct option opts[] = {
|
||||||
|
@ -159,7 +158,7 @@ data_dir(void)
|
||||||
}
|
}
|
||||||
|
|
||||||
static int
|
static int
|
||||||
serve(const char *host, int port, const char *dir)
|
serve(struct conf *conf, const char *host, int port, const char *dir)
|
||||||
{
|
{
|
||||||
struct addrinfo hints, *res, *res0;
|
struct addrinfo hints, *res, *res0;
|
||||||
int r, error, saved_errno, sock = -1;
|
int r, error, saved_errno, sock = -1;
|
||||||
|
@ -210,12 +209,12 @@ serve(const char *host, int port, const char *dir)
|
||||||
event_init();
|
event_init();
|
||||||
|
|
||||||
/* cheating */
|
/* cheating */
|
||||||
conf.sock4 = sock;
|
conf->sock4 = sock;
|
||||||
event_set(&conf.evsock4, conf.sock4, EV_READ|EV_PERSIST,
|
event_set(&conf->evsock4, conf->sock4, EV_READ|EV_PERSIST,
|
||||||
do_accept, NULL);
|
do_accept, conf);
|
||||||
|
|
||||||
server_init(NULL, NULL, NULL);
|
server_init(NULL, NULL, NULL);
|
||||||
if (server_configure_done(&conf) == -1)
|
if (server_configure_done(conf) == -1)
|
||||||
fatalx("server configuration failed");
|
fatalx("server configuration failed");
|
||||||
|
|
||||||
log_info("serving %s on port %d", dir, port);
|
log_info("serving %s on port %d", dir, port);
|
||||||
|
@ -237,6 +236,7 @@ usage(void)
|
||||||
int
|
int
|
||||||
main(int argc, char **argv)
|
main(int argc, char **argv)
|
||||||
{
|
{
|
||||||
|
struct conf *conf;
|
||||||
struct vhost *host;
|
struct vhost *host;
|
||||||
struct location *loc;
|
struct location *loc;
|
||||||
const char *errstr, *certs_dir = NULL, *hostname = "localhost";
|
const char *errstr, *certs_dir = NULL, *hostname = "localhost";
|
||||||
|
@ -247,7 +247,7 @@ main(int argc, char **argv)
|
||||||
|
|
||||||
log_init(1, LOG_DAEMON);
|
log_init(1, LOG_DAEMON);
|
||||||
log_setverbose(0);
|
log_setverbose(0);
|
||||||
config_init();
|
conf = config_new();
|
||||||
|
|
||||||
while ((ch = getopt_long(argc, argv, "d:H:hp:Vv", opts, NULL)) != -1) {
|
while ((ch = getopt_long(argc, argv, "d:H:hp:Vv", opts, NULL)) != -1) {
|
||||||
switch (ch) {
|
switch (ch) {
|
||||||
|
@ -261,7 +261,7 @@ main(int argc, char **argv)
|
||||||
usage();
|
usage();
|
||||||
break;
|
break;
|
||||||
case 'p':
|
case 'p':
|
||||||
conf.port = strtonum(optarg, 0, UINT16_MAX, &errstr);
|
conf->port = strtonum(optarg, 0, UINT16_MAX, &errstr);
|
||||||
if (errstr)
|
if (errstr)
|
||||||
fatalx("port number is %s: %s", errstr,
|
fatalx("port number is %s: %s", errstr,
|
||||||
optarg);
|
optarg);
|
||||||
|
@ -281,14 +281,14 @@ main(int argc, char **argv)
|
||||||
usage();
|
usage();
|
||||||
|
|
||||||
/* prepare the configuration */
|
/* prepare the configuration */
|
||||||
init_mime(&conf.mime);
|
init_mime(&conf->mime);
|
||||||
|
|
||||||
if (certs_dir == NULL)
|
if (certs_dir == NULL)
|
||||||
certs_dir = data_dir();
|
certs_dir = data_dir();
|
||||||
|
|
||||||
/* set up the implicit vhost and location */
|
/* set up the implicit vhost and location */
|
||||||
host = xcalloc(1, sizeof(*host));
|
host = xcalloc(1, sizeof(*host));
|
||||||
TAILQ_INSERT_HEAD(&conf.hosts, host, vhosts);
|
TAILQ_INSERT_HEAD(&conf->hosts, host, vhosts);
|
||||||
|
|
||||||
loc = xcalloc(1, sizeof(*loc));
|
loc = xcalloc(1, sizeof(*loc));
|
||||||
loc->fcgi = -1;
|
loc->fcgi = -1;
|
||||||
|
@ -315,5 +315,5 @@ main(int argc, char **argv)
|
||||||
/* start the server */
|
/* start the server */
|
||||||
signal(SIGPIPE, SIG_IGN);
|
signal(SIGPIPE, SIG_IGN);
|
||||||
setproctitle("%s", loc->dir);
|
setproctitle("%s", loc->dir);
|
||||||
return serve(hostname, conf.port, loc->dir);
|
return serve(conf, hostname, conf->port, loc->dir);
|
||||||
}
|
}
|
||||||
|
|
39
gmid.c
39
gmid.c
|
@ -67,8 +67,6 @@ int debug, verbose;
|
||||||
const char *config_path = "/etc/gmid.conf";
|
const char *config_path = "/etc/gmid.conf";
|
||||||
const char *pidfile;
|
const char *pidfile;
|
||||||
|
|
||||||
struct conf conf;
|
|
||||||
|
|
||||||
static void
|
static void
|
||||||
usage(void)
|
usage(void)
|
||||||
{
|
{
|
||||||
|
@ -82,6 +80,7 @@ usage(void)
|
||||||
void
|
void
|
||||||
log_request(struct client *c, char *meta, size_t l)
|
log_request(struct client *c, char *meta, size_t l)
|
||||||
{
|
{
|
||||||
|
struct conf *conf = c->conf;
|
||||||
char hbuf[NI_MAXHOST], sbuf[NI_MAXSERV], b[GEMINI_URL_LEN];
|
char hbuf[NI_MAXHOST], sbuf[NI_MAXSERV], b[GEMINI_URL_LEN];
|
||||||
char *fmted;
|
char *fmted;
|
||||||
const char *t;
|
const char *t;
|
||||||
|
@ -129,7 +128,7 @@ log_request(struct client *c, char *meta, size_t l)
|
||||||
if (ec == -1)
|
if (ec == -1)
|
||||||
err(1, "asprintf");
|
err(1, "asprintf");
|
||||||
|
|
||||||
proc_compose(conf.ps, PROC_LOGGER, IMSG_LOG_REQUEST,
|
proc_compose(conf->ps, PROC_LOGGER, IMSG_LOG_REQUEST,
|
||||||
fmted, ec + 1);
|
fmted, ec + 1);
|
||||||
|
|
||||||
free(fmted);
|
free(fmted);
|
||||||
|
@ -166,6 +165,7 @@ write_pidfile(const char *pidfile)
|
||||||
int
|
int
|
||||||
main(int argc, char **argv)
|
main(int argc, char **argv)
|
||||||
{
|
{
|
||||||
|
struct conf *conf;
|
||||||
struct privsep *ps;
|
struct privsep *ps;
|
||||||
const char *errstr, *title = NULL;
|
const char *errstr, *title = NULL;
|
||||||
size_t i;
|
size_t i;
|
||||||
|
@ -178,7 +178,6 @@ main(int argc, char **argv)
|
||||||
|
|
||||||
/* log to stderr until daemonized */
|
/* log to stderr until daemonized */
|
||||||
log_init(1, LOG_DAEMON);
|
log_init(1, LOG_DAEMON);
|
||||||
config_init();
|
|
||||||
|
|
||||||
while ((ch = getopt_long(argc, argv, opts, longopts, NULL)) != -1) {
|
while ((ch = getopt_long(argc, argv, opts, longopts, NULL)) != -1) {
|
||||||
switch (ch) {
|
switch (ch) {
|
||||||
|
@ -229,8 +228,10 @@ main(int argc, char **argv)
|
||||||
if (argc - optind != 0)
|
if (argc - optind != 0)
|
||||||
usage();
|
usage();
|
||||||
|
|
||||||
parse_conf(config_path);
|
conf = config_new();
|
||||||
if (*conf.chroot != '\0' && *conf.user == '\0')
|
|
||||||
|
parse_conf(conf, config_path);
|
||||||
|
if (*conf->chroot != '\0' && *conf->user == '\0')
|
||||||
fatalx("can't chroot without a user to switch to after.");
|
fatalx("can't chroot without a user to switch to after.");
|
||||||
|
|
||||||
if (conftest) {
|
if (conftest) {
|
||||||
|
@ -242,23 +243,23 @@ main(int argc, char **argv)
|
||||||
|
|
||||||
if ((ps = calloc(1, sizeof(*ps))) == NULL)
|
if ((ps = calloc(1, sizeof(*ps))) == NULL)
|
||||||
fatal("calloc");
|
fatal("calloc");
|
||||||
ps->ps_env = &conf;
|
ps->ps_env = conf;
|
||||||
conf.ps = ps;
|
conf->ps = ps;
|
||||||
if (*conf.user) {
|
if (*conf->user) {
|
||||||
if (geteuid())
|
if (geteuid())
|
||||||
fatalx("need root privileges");
|
fatalx("need root privileges");
|
||||||
if ((ps->ps_pw = getpwnam(conf.user)) == NULL)
|
if ((ps->ps_pw = getpwnam(conf->user)) == NULL)
|
||||||
fatalx("unknown user %s", conf.user);
|
fatalx("unknown user %s", conf->user);
|
||||||
}
|
}
|
||||||
|
|
||||||
ps->ps_instances[PROC_SERVER] = conf.prefork;
|
ps->ps_instances[PROC_SERVER] = conf->prefork;
|
||||||
ps->ps_instance = proc_instance;
|
ps->ps_instance = proc_instance;
|
||||||
if (title != NULL)
|
if (title != NULL)
|
||||||
ps->ps_title[proc_id] = title;
|
ps->ps_title[proc_id] = title;
|
||||||
|
|
||||||
if (*conf.chroot != '\0') {
|
if (*conf->chroot != '\0') {
|
||||||
for (i = 0; i < nitems(procs); ++i)
|
for (i = 0; i < nitems(procs); ++i)
|
||||||
procs[i].p_chroot = conf.chroot;
|
procs[i].p_chroot = conf->chroot;
|
||||||
}
|
}
|
||||||
|
|
||||||
log_init(debug, LOG_DAEMON);
|
log_init(debug, LOG_DAEMON);
|
||||||
|
@ -293,11 +294,11 @@ main(int argc, char **argv)
|
||||||
|
|
||||||
proc_connect(ps);
|
proc_connect(ps);
|
||||||
|
|
||||||
if (main_configure(&conf) == -1)
|
if (main_configure(conf) == -1)
|
||||||
fatal("configuration failed");
|
fatal("configuration failed");
|
||||||
|
|
||||||
event_dispatch();
|
event_dispatch();
|
||||||
main_shutdown(&conf);
|
main_shutdown(conf);
|
||||||
/* NOTREACHED */
|
/* NOTREACHED */
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -343,8 +344,8 @@ main_reload(struct conf *conf)
|
||||||
}
|
}
|
||||||
|
|
||||||
log_debug("%s: config file %s", __func__, config_path);
|
log_debug("%s: config file %s", __func__, config_path);
|
||||||
config_free();
|
config_purge(conf);
|
||||||
parse_conf(config_path); /* XXX should handle error here */
|
parse_conf(conf, config_path); /* XXX should handle error here */
|
||||||
|
|
||||||
main_configure(conf);
|
main_configure(conf);
|
||||||
}
|
}
|
||||||
|
@ -416,7 +417,7 @@ static void __dead
|
||||||
main_shutdown(struct conf *conf)
|
main_shutdown(struct conf *conf)
|
||||||
{
|
{
|
||||||
proc_kill(conf->ps);
|
proc_kill(conf->ps);
|
||||||
config_free();
|
config_purge(conf);
|
||||||
free(conf->ps);
|
free(conf->ps);
|
||||||
/* free(conf); */
|
/* free(conf); */
|
||||||
|
|
||||||
|
|
10
gmid.h
10
gmid.h
|
@ -230,7 +230,6 @@ struct conf {
|
||||||
};
|
};
|
||||||
|
|
||||||
extern const char *config_path;
|
extern const char *config_path;
|
||||||
extern struct conf conf;
|
|
||||||
|
|
||||||
extern int servpipes[PROC_MAX_INSTANCES];
|
extern int servpipes[PROC_MAX_INSTANCES];
|
||||||
extern int privsep_process;
|
extern int privsep_process;
|
||||||
|
@ -247,6 +246,7 @@ enum {
|
||||||
};
|
};
|
||||||
|
|
||||||
struct client {
|
struct client {
|
||||||
|
struct conf *conf;
|
||||||
uint32_t id;
|
uint32_t id;
|
||||||
struct tls *ctx;
|
struct tls *ctx;
|
||||||
char *req;
|
char *req;
|
||||||
|
@ -339,14 +339,14 @@ void load_local_cert(struct vhost*, const char*, const char*);
|
||||||
void log_request(struct client *, char *, size_t);
|
void log_request(struct client *, char *, size_t);
|
||||||
|
|
||||||
/* config.c */
|
/* config.c */
|
||||||
void config_init(void);
|
struct conf *config_new(void);
|
||||||
void config_free(void);
|
void config_purge(struct conf *);
|
||||||
int config_send(struct conf *);
|
int config_send(struct conf *);
|
||||||
int config_recv(struct conf *, struct imsg *);
|
int config_recv(struct conf *, struct imsg *);
|
||||||
|
|
||||||
/* parse.y */
|
/* parse.y */
|
||||||
void yyerror(const char*, ...);
|
void yyerror(const char*, ...);
|
||||||
void parse_conf(const char*);
|
void parse_conf(struct conf *, const char*);
|
||||||
void print_conf(void);
|
void print_conf(void);
|
||||||
int cmdline_symset(char *);
|
int cmdline_symset(char *);
|
||||||
|
|
||||||
|
@ -355,7 +355,7 @@ void init_mime(struct mime*);
|
||||||
int add_mime(struct mime*, const char*, const char*);
|
int add_mime(struct mime*, const char*, const char*);
|
||||||
int load_default_mime(struct mime*);
|
int load_default_mime(struct mime*);
|
||||||
void sort_mime(struct mime *);
|
void sort_mime(struct mime *);
|
||||||
const char *mime(struct vhost*, const char*);
|
const char *mime(struct conf *, struct vhost*, const char*);
|
||||||
void free_mime(struct mime *);
|
void free_mime(struct mime *);
|
||||||
|
|
||||||
/* server.c */
|
/* server.c */
|
||||||
|
|
4
mime.c
4
mime.c
|
@ -136,7 +136,7 @@ mime_find(const void *a, const void *b)
|
||||||
}
|
}
|
||||||
|
|
||||||
const char *
|
const char *
|
||||||
mime(struct vhost *host, const char *path)
|
mime(struct conf *conf, struct vhost *host, const char *path)
|
||||||
{
|
{
|
||||||
const char *def, *ext;
|
const char *def, *ext;
|
||||||
struct etm *t;
|
struct etm *t;
|
||||||
|
@ -146,7 +146,7 @@ mime(struct vhost *host, const char *path)
|
||||||
if ((ext = path_ext(path)) == NULL)
|
if ((ext = path_ext(path)) == NULL)
|
||||||
return def;
|
return def;
|
||||||
|
|
||||||
t = bsearch(ext, conf.mime.t, conf.mime.len, sizeof(*conf.mime.t),
|
t = bsearch(ext, conf->mime.t, conf->mime.len, sizeof(*conf->mime.t),
|
||||||
mime_find);
|
mime_find);
|
||||||
if (t != NULL)
|
if (t != NULL)
|
||||||
return t->mime;
|
return t->mime;
|
||||||
|
|
46
parse.y
46
parse.y
|
@ -35,6 +35,8 @@
|
||||||
|
|
||||||
#include "log.h"
|
#include "log.h"
|
||||||
|
|
||||||
|
struct conf *conf;
|
||||||
|
|
||||||
TAILQ_HEAD(files, file) files = TAILQ_HEAD_INITIALIZER(files);
|
TAILQ_HEAD(files, file) files = TAILQ_HEAD_INITIALIZER(files);
|
||||||
static struct file {
|
static struct file {
|
||||||
TAILQ_ENTRY(file) entry;
|
TAILQ_ENTRY(file) entry;
|
||||||
|
@ -214,22 +216,22 @@ varset : STRING '=' string {
|
||||||
;
|
;
|
||||||
|
|
||||||
option : CHROOT string {
|
option : CHROOT string {
|
||||||
if (strlcpy(conf.chroot, $2, sizeof(conf.chroot)) >=
|
if (strlcpy(conf->chroot, $2, sizeof(conf->chroot)) >=
|
||||||
sizeof(conf.chroot))
|
sizeof(conf->chroot))
|
||||||
yyerror("chroot path too long");
|
yyerror("chroot path too long");
|
||||||
free($2);
|
free($2);
|
||||||
}
|
}
|
||||||
| IPV6 bool { conf.ipv6 = $2; }
|
| IPV6 bool { conf->ipv6 = $2; }
|
||||||
| PORT NUM { conf.port = check_port_num($2); }
|
| PORT NUM { conf->port = check_port_num($2); }
|
||||||
| PREFORK NUM { conf.prefork = check_prefork_num($2); }
|
| PREFORK NUM { conf->prefork = check_prefork_num($2); }
|
||||||
| PROTOCOLS string {
|
| PROTOCOLS string {
|
||||||
if (tls_config_parse_protocols(&conf.protos, $2) == -1)
|
if (tls_config_parse_protocols(&conf->protos, $2) == -1)
|
||||||
yyerror("invalid protocols string \"%s\"", $2);
|
yyerror("invalid protocols string \"%s\"", $2);
|
||||||
free($2);
|
free($2);
|
||||||
}
|
}
|
||||||
| USER string {
|
| USER string {
|
||||||
if (strlcpy(conf.user, $2, sizeof(conf.user)) >=
|
if (strlcpy(conf->user, $2, sizeof(conf->user)) >=
|
||||||
sizeof(conf.user))
|
sizeof(conf->user))
|
||||||
yyerror("user name too long");
|
yyerror("user name too long");
|
||||||
free($2);
|
free($2);
|
||||||
}
|
}
|
||||||
|
@ -237,7 +239,7 @@ option : CHROOT string {
|
||||||
|
|
||||||
vhost : SERVER string {
|
vhost : SERVER string {
|
||||||
host = new_vhost();
|
host = new_vhost();
|
||||||
TAILQ_INSERT_HEAD(&conf.hosts, host, vhosts);
|
TAILQ_INSERT_HEAD(&conf->hosts, host, vhosts);
|
||||||
|
|
||||||
loc = new_location();
|
loc = new_location();
|
||||||
TAILQ_INSERT_HEAD(&host->locations, loc, locations);
|
TAILQ_INSERT_HEAD(&host->locations, loc, locations);
|
||||||
|
@ -473,7 +475,7 @@ medianames_l : medianames_l medianamesl
|
||||||
;
|
;
|
||||||
|
|
||||||
medianamesl : numberstring {
|
medianamesl : numberstring {
|
||||||
if (add_mime(&conf.mime, current_media, $1) == -1)
|
if (add_mime(&conf->mime, current_media, $1) == -1)
|
||||||
err(1, "add_mime");
|
err(1, "add_mime");
|
||||||
free($1);
|
free($1);
|
||||||
}
|
}
|
||||||
|
@ -907,10 +909,12 @@ popfile(void)
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
parse_conf(const char *filename)
|
parse_conf(struct conf *c, const char *filename)
|
||||||
{
|
{
|
||||||
struct sym *sym, *next;
|
struct sym *sym, *next;
|
||||||
|
|
||||||
|
conf = c;
|
||||||
|
|
||||||
file = pushfile(filename, 0);
|
file = pushfile(filename, 0);
|
||||||
if (file == NULL)
|
if (file == NULL)
|
||||||
exit(1);
|
exit(1);
|
||||||
|
@ -943,17 +947,17 @@ print_conf(void)
|
||||||
/* struct envlist *e; */
|
/* struct envlist *e; */
|
||||||
/* struct alist *a; */
|
/* struct alist *a; */
|
||||||
|
|
||||||
if (*conf.chroot != '\0')
|
if (*conf->chroot != '\0')
|
||||||
printf("chroot \"%s\"\n", conf.chroot);
|
printf("chroot \"%s\"\n", conf->chroot);
|
||||||
printf("ipv6 %s\n", conf.ipv6 ? "on" : "off");
|
printf("ipv6 %s\n", conf->ipv6 ? "on" : "off");
|
||||||
/* XXX: defined mimes? */
|
/* XXX: defined mimes? */
|
||||||
printf("port %d\n", conf.port);
|
printf("port %d\n", conf->port);
|
||||||
printf("prefork %d\n", conf.prefork);
|
printf("prefork %d\n", conf->prefork);
|
||||||
/* XXX: protocols? */
|
/* XXX: protocols? */
|
||||||
if (*conf.user != '\0')
|
if (*conf->user != '\0')
|
||||||
printf("user \"%s\"\n", conf.user);
|
printf("user \"%s\"\n", conf->user);
|
||||||
|
|
||||||
TAILQ_FOREACH(h, &conf.hosts, vhosts) {
|
TAILQ_FOREACH(h, &conf->hosts, vhosts) {
|
||||||
printf("\nserver \"%s\" {\n", h->domain);
|
printf("\nserver \"%s\" {\n", h->domain);
|
||||||
printf(" cert \"%s\"\n", h->cert);
|
printf(" cert \"%s\"\n", h->cert);
|
||||||
printf(" key \"%s\"\n", h->key);
|
printf(" key \"%s\"\n", h->key);
|
||||||
|
@ -1126,7 +1130,7 @@ fastcgi_conf(const char *path, const char *port)
|
||||||
struct fcgi *f;
|
struct fcgi *f;
|
||||||
int i = 0;
|
int i = 0;
|
||||||
|
|
||||||
TAILQ_FOREACH(f, &conf.fcgi, fcgi) {
|
TAILQ_FOREACH(f, &conf->fcgi, fcgi) {
|
||||||
if (!strcmp(f->path, path) &&
|
if (!strcmp(f->path, path) &&
|
||||||
((port == NULL && *f->port == '\0') ||
|
((port == NULL && *f->port == '\0') ||
|
||||||
!strcmp(f->port, port)))
|
!strcmp(f->port, port)))
|
||||||
|
@ -1139,7 +1143,7 @@ fastcgi_conf(const char *path, const char *port)
|
||||||
(void)strlcpy(f->path, path, sizeof(f->path));
|
(void)strlcpy(f->path, path, sizeof(f->path));
|
||||||
if (port != NULL)
|
if (port != NULL)
|
||||||
(void)strlcpy(f->port, port, sizeof(f->port));
|
(void)strlcpy(f->port, port, sizeof(f->port));
|
||||||
TAILQ_INSERT_TAIL(&conf.fcgi, f, fcgi);
|
TAILQ_INSERT_TAIL(&conf->fcgi, f, fcgi);
|
||||||
|
|
||||||
return f->id;
|
return f->id;
|
||||||
}
|
}
|
||||||
|
|
|
@ -19,9 +19,6 @@
|
||||||
|
|
||||||
#include "../gmid.h"
|
#include "../gmid.h"
|
||||||
|
|
||||||
/* to make the linker happy */
|
|
||||||
struct conf conf;
|
|
||||||
|
|
||||||
const struct suite {
|
const struct suite {
|
||||||
const char *src;
|
const char *src;
|
||||||
const char *res;
|
const char *res;
|
||||||
|
|
28
server.c
28
server.c
|
@ -356,7 +356,7 @@ open_file(struct client *c)
|
||||||
switch (check_path(c, c->iri.path, &c->pfd)) {
|
switch (check_path(c, c->iri.path, &c->pfd)) {
|
||||||
case FILE_EXISTS:
|
case FILE_EXISTS:
|
||||||
c->type = REQUEST_FILE;
|
c->type = REQUEST_FILE;
|
||||||
start_reply(c, SUCCESS, mime(c->host, c->iri.path));
|
start_reply(c, SUCCESS, mime(c->conf, c->host, c->iri.path));
|
||||||
return;
|
return;
|
||||||
|
|
||||||
case FILE_DIRECTORY:
|
case FILE_DIRECTORY:
|
||||||
|
@ -388,6 +388,7 @@ static void
|
||||||
handle_handshake(int fd, short ev, void *d)
|
handle_handshake(int fd, short ev, void *d)
|
||||||
{
|
{
|
||||||
struct client *c = d;
|
struct client *c = d;
|
||||||
|
struct conf *conf = c->conf;
|
||||||
struct vhost *h;
|
struct vhost *h;
|
||||||
struct alist *a;
|
struct alist *a;
|
||||||
const char *servname;
|
const char *servname;
|
||||||
|
@ -433,7 +434,7 @@ handle_handshake(int fd, short ev, void *d)
|
||||||
goto err;
|
goto err;
|
||||||
}
|
}
|
||||||
|
|
||||||
TAILQ_FOREACH(h, &conf.hosts, vhosts) {
|
TAILQ_FOREACH(h, &conf->hosts, vhosts) {
|
||||||
if (matches(h->domain, c->domain))
|
if (matches(h->domain, c->domain))
|
||||||
goto found;
|
goto found;
|
||||||
TAILQ_FOREACH(a, &h->aliases, aliases) {
|
TAILQ_FOREACH(a, &h->aliases, aliases) {
|
||||||
|
@ -478,6 +479,7 @@ strip_path(const char *path, int strip)
|
||||||
static void
|
static void
|
||||||
fmt_sbuf(const char *fmt, struct client *c, const char *path)
|
fmt_sbuf(const char *fmt, struct client *c, const char *path)
|
||||||
{
|
{
|
||||||
|
struct conf *conf = c->conf;
|
||||||
size_t i;
|
size_t i;
|
||||||
char buf[32];
|
char buf[32];
|
||||||
|
|
||||||
|
@ -507,7 +509,7 @@ fmt_sbuf(const char *fmt, struct client *c, const char *path)
|
||||||
strlcat(c->sbuf, c->iri.query, sizeof(c->sbuf));
|
strlcat(c->sbuf, c->iri.query, sizeof(c->sbuf));
|
||||||
break;
|
break;
|
||||||
case 'P':
|
case 'P':
|
||||||
snprintf(buf, sizeof(buf), "%d", conf.port);
|
snprintf(buf, sizeof(buf), "%d", conf->port);
|
||||||
strlcat(c->sbuf, buf, sizeof(c->sbuf));
|
strlcat(c->sbuf, buf, sizeof(c->sbuf));
|
||||||
memset(buf, 0, sizeof(buf));
|
memset(buf, 0, sizeof(buf));
|
||||||
break;
|
break;
|
||||||
|
@ -740,7 +742,7 @@ apply_fastcgi(struct client *c)
|
||||||
if ((id = vhost_fastcgi(c->host, c->iri.path)) == -1)
|
if ((id = vhost_fastcgi(c->host, c->iri.path)) == -1)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
TAILQ_FOREACH(f, &conf.fcgi, fcgi) {
|
TAILQ_FOREACH(f, &c->conf->fcgi, fcgi) {
|
||||||
if (i == id)
|
if (i == id)
|
||||||
break;
|
break;
|
||||||
++i;
|
++i;
|
||||||
|
@ -828,7 +830,7 @@ open_dir(struct client *c)
|
||||||
switch (check_path(c, c->iri.path, &c->pfd)) {
|
switch (check_path(c, c->iri.path, &c->pfd)) {
|
||||||
case FILE_EXISTS:
|
case FILE_EXISTS:
|
||||||
c->type = REQUEST_FILE;
|
c->type = REQUEST_FILE;
|
||||||
start_reply(c, SUCCESS, mime(c->host, c->iri.path));
|
start_reply(c, SUCCESS, mime(c->conf, c->host, c->iri.path));
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case FILE_DIRECTORY:
|
case FILE_DIRECTORY:
|
||||||
|
@ -1302,6 +1304,7 @@ client_close(struct client *c)
|
||||||
void
|
void
|
||||||
do_accept(int sock, short et, void *d)
|
do_accept(int sock, short et, void *d)
|
||||||
{
|
{
|
||||||
|
struct conf *conf = d;
|
||||||
struct client *c;
|
struct client *c;
|
||||||
struct sockaddr_storage addr;
|
struct sockaddr_storage addr;
|
||||||
struct sockaddr *saddr;
|
struct sockaddr *saddr;
|
||||||
|
@ -1320,6 +1323,7 @@ do_accept(int sock, short et, void *d)
|
||||||
mark_nonblock(fd);
|
mark_nonblock(fd);
|
||||||
|
|
||||||
c = xcalloc(1, sizeof(*c));
|
c = xcalloc(1, sizeof(*c));
|
||||||
|
c->conf = conf;
|
||||||
c->id = ++server_client_id;
|
c->id = ++server_client_id;
|
||||||
c->fd = fd;
|
c->fd = fd;
|
||||||
c->pfd = -1;
|
c->pfd = -1;
|
||||||
|
@ -1369,7 +1373,7 @@ add_keypair(struct vhost *h, struct tls_config *conf)
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
setup_tls(void)
|
setup_tls(struct conf *conf)
|
||||||
{
|
{
|
||||||
struct tls_config *tlsconf;
|
struct tls_config *tlsconf;
|
||||||
struct vhost *h;
|
struct vhost *h;
|
||||||
|
@ -1386,11 +1390,11 @@ setup_tls(void)
|
||||||
tls_config_verify_client_optional(tlsconf);
|
tls_config_verify_client_optional(tlsconf);
|
||||||
tls_config_insecure_noverifycert(tlsconf);
|
tls_config_insecure_noverifycert(tlsconf);
|
||||||
|
|
||||||
if (tls_config_set_protocols(tlsconf, conf.protos) == -1)
|
if (tls_config_set_protocols(tlsconf, conf->protos) == -1)
|
||||||
fatalx("tls_config_set_protocols: %s",
|
fatalx("tls_config_set_protocols: %s",
|
||||||
tls_config_error(tlsconf));
|
tls_config_error(tlsconf));
|
||||||
|
|
||||||
h = TAILQ_FIRST(&conf.hosts);
|
h = TAILQ_FIRST(&conf->hosts);
|
||||||
|
|
||||||
/* we need to set something, then we can add how many key we want */
|
/* we need to set something, then we can add how many key we want */
|
||||||
if (tls_config_set_keypair_mem(tlsconf, h->cert, h->certlen,
|
if (tls_config_set_keypair_mem(tlsconf, h->cert, h->certlen,
|
||||||
|
@ -1416,12 +1420,12 @@ setup_tls(void)
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
load_vhosts(void)
|
load_vhosts(struct conf *conf)
|
||||||
{
|
{
|
||||||
struct vhost *h;
|
struct vhost *h;
|
||||||
struct location *l;
|
struct location *l;
|
||||||
|
|
||||||
TAILQ_FOREACH(h, &conf.hosts, vhosts) {
|
TAILQ_FOREACH(h, &conf->hosts, vhosts) {
|
||||||
TAILQ_FOREACH(l, &h->locations, locations) {
|
TAILQ_FOREACH(l, &h->locations, locations) {
|
||||||
if (*l->dir == '\0')
|
if (*l->dir == '\0')
|
||||||
continue;
|
continue;
|
||||||
|
@ -1461,8 +1465,8 @@ server_configure_done(struct conf *conf)
|
||||||
if (load_default_mime(&conf->mime) == -1)
|
if (load_default_mime(&conf->mime) == -1)
|
||||||
fatal("can't load default mime");
|
fatal("can't load default mime");
|
||||||
sort_mime(&conf->mime);
|
sort_mime(&conf->mime);
|
||||||
setup_tls();
|
setup_tls(conf);
|
||||||
load_vhosts();
|
load_vhosts(conf);
|
||||||
if (conf->sock4 != -1)
|
if (conf->sock4 != -1)
|
||||||
event_add(&conf->evsock4, NULL);
|
event_add(&conf->evsock4, NULL);
|
||||||
if (conf->sock6 != -1)
|
if (conf->sock6 != -1)
|
||||||
|
|
Loading…
Reference in New Issue