2021-01-15 10:17:43 +01:00
|
|
|
%{
|
|
|
|
|
|
|
|
/*
|
2024-01-30 10:30:50 +01:00
|
|
|
* Copyright (c) 2021-2024 Omar Polo <op@omarpolo.com>
|
2021-07-09 13:25:25 +02:00
|
|
|
* Copyright (c) 2018 Florian Obser <florian@openbsd.org>
|
|
|
|
* Copyright (c) 2004, 2005 Esben Norby <norby@openbsd.org>
|
|
|
|
* Copyright (c) 2004 Ryan McBride <mcbride@openbsd.org>
|
|
|
|
* Copyright (c) 2002, 2003, 2004 Henning Brauer <henning@openbsd.org>
|
|
|
|
* Copyright (c) 2001 Markus Friedl. All rights reserved.
|
|
|
|
* Copyright (c) 2001 Daniel Hartmeier. All rights reserved.
|
|
|
|
* Copyright (c) 2001 Theo de Raadt. All rights reserved.
|
2021-01-15 10:17:43 +01:00
|
|
|
*
|
|
|
|
* Permission to use, copy, modify, and distribute this software for any
|
|
|
|
* purpose with or without fee is hereby granted, provided that the above
|
|
|
|
* copyright notice and this permission notice appear in all copies.
|
|
|
|
*
|
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
|
|
|
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
|
|
|
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
|
|
|
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
|
|
|
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
|
|
|
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
|
|
|
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
|
|
|
*/
|
|
|
|
|
2022-02-03 11:10:32 +01:00
|
|
|
#include "gmid.h"
|
|
|
|
|
2021-06-16 16:43:16 +02:00
|
|
|
#include <ctype.h>
|
2021-02-10 12:53:05 +01:00
|
|
|
#include <errno.h>
|
2022-10-05 17:10:44 +02:00
|
|
|
#include <netdb.h>
|
2021-02-06 18:22:37 +01:00
|
|
|
#include <stdarg.h>
|
2021-01-15 10:17:43 +01:00
|
|
|
#include <stdio.h>
|
2021-06-16 16:43:16 +02:00
|
|
|
#include <stdlib.h>
|
2021-01-28 18:50:22 +01:00
|
|
|
#include <string.h>
|
2023-08-07 11:34:19 +02:00
|
|
|
#include <syslog.h>
|
2021-01-15 10:17:43 +01:00
|
|
|
|
2023-06-05 19:07:52 +02:00
|
|
|
#include "log.h"
|
|
|
|
|
2023-06-09 19:18:04 +02:00
|
|
|
struct conf *conf;
|
|
|
|
|
2023-08-25 14:19:00 +02:00
|
|
|
static const char *default_host = NULL;
|
2023-06-23 23:03:29 +02:00
|
|
|
static uint16_t default_port = 1965;
|
|
|
|
|
2021-07-09 13:25:25 +02:00
|
|
|
TAILQ_HEAD(files, file) files = TAILQ_HEAD_INITIALIZER(files);
|
|
|
|
static struct file {
|
|
|
|
TAILQ_ENTRY(file) entry;
|
|
|
|
FILE *stream;
|
|
|
|
char *name;
|
2024-01-30 10:28:54 +01:00
|
|
|
size_t ungetpos;
|
2021-07-09 13:25:25 +02:00
|
|
|
size_t ungetsize;
|
|
|
|
u_char *ungetbuf;
|
|
|
|
int eof_reached;
|
|
|
|
int lineno;
|
|
|
|
int errors;
|
|
|
|
} *file, *topfile;
|
|
|
|
|
|
|
|
struct file *pushfile(const char *, int);
|
|
|
|
int popfile(void);
|
|
|
|
int yyparse(void);
|
|
|
|
int yylex(void);
|
|
|
|
void yyerror(const char *, ...)
|
|
|
|
__attribute__((__format__ (printf, 1, 2)))
|
|
|
|
__attribute__((__nonnull__ (1)));
|
2021-07-13 13:30:54 +02:00
|
|
|
void yywarn(const char *, ...)
|
|
|
|
__attribute__((__format__ (printf, 1, 2)))
|
|
|
|
__attribute__((__nonnull__ (1)));
|
2021-07-09 13:25:25 +02:00
|
|
|
int kw_cmp(const void *, const void *);
|
|
|
|
int lookup(char *);
|
|
|
|
int igetc(void);
|
|
|
|
int lgetc(int);
|
|
|
|
void lungetc(int);
|
|
|
|
int findeol(void);
|
2021-06-16 16:51:57 +02:00
|
|
|
|
2021-01-15 10:17:43 +01:00
|
|
|
/*
|
|
|
|
* #define YYDEBUG 1
|
|
|
|
* int yydebug = 1;
|
|
|
|
*/
|
|
|
|
|
2021-06-29 14:17:40 +02:00
|
|
|
TAILQ_HEAD(symhead, sym) symhead = TAILQ_HEAD_INITIALIZER(symhead);
|
|
|
|
struct sym {
|
|
|
|
TAILQ_ENTRY(sym) entry;
|
|
|
|
int used;
|
|
|
|
int persist;
|
|
|
|
char *name;
|
|
|
|
char *val;
|
|
|
|
};
|
|
|
|
|
2021-07-09 13:25:25 +02:00
|
|
|
int symset(const char *, const char *, int);
|
|
|
|
char *symget(const char *);
|
2021-01-27 17:45:45 +01:00
|
|
|
|
2021-02-01 12:08:57 +01:00
|
|
|
char *ensure_absolute_path(char*);
|
2021-02-06 18:22:37 +01:00
|
|
|
int check_block_code(int);
|
|
|
|
char *check_block_fmt(char*);
|
|
|
|
int check_strip_no(int);
|
2021-02-07 13:05:32 +01:00
|
|
|
int check_prefork_num(int);
|
2021-02-10 17:37:08 +01:00
|
|
|
void advance_loc(void);
|
2022-01-02 17:33:28 +01:00
|
|
|
void advance_proxy(void);
|
2022-10-05 17:30:22 +02:00
|
|
|
int fastcgi_conf(const char *, const char *);
|
2022-09-10 11:48:30 +02:00
|
|
|
void add_param(char *, char *);
|
2022-10-05 17:10:44 +02:00
|
|
|
int getservice(const char *);
|
2023-06-23 23:03:29 +02:00
|
|
|
void listen_on(const char *, const char *);
|
2021-07-09 13:25:25 +02:00
|
|
|
|
|
|
|
static struct vhost *host;
|
|
|
|
static struct location *loc;
|
2022-01-02 17:33:28 +01:00
|
|
|
static struct proxy *proxy;
|
2022-02-26 15:00:20 +01:00
|
|
|
static char *current_media;
|
2021-07-09 13:25:25 +02:00
|
|
|
static int errors;
|
|
|
|
|
|
|
|
typedef struct {
|
|
|
|
union {
|
|
|
|
char *string;
|
|
|
|
int number;
|
|
|
|
} v;
|
|
|
|
int lineno;
|
|
|
|
} YYSTYPE;
|
2021-01-15 10:17:43 +01:00
|
|
|
|
2023-06-13 13:00:07 +02:00
|
|
|
#define YYSTYPE YYSTYPE
|
|
|
|
|
2021-01-15 10:17:43 +01:00
|
|
|
%}
|
|
|
|
|
|
|
|
/* for bison: */
|
|
|
|
/* %define parse.error verbose */
|
|
|
|
|
2023-07-24 10:50:49 +02:00
|
|
|
%token ACCESS ALIAS AUTO
|
2021-07-19 09:39:13 +02:00
|
|
|
%token BLOCK
|
2024-01-30 10:30:50 +01:00
|
|
|
%token CA CERT CHROOT CLIENT
|
2021-07-19 09:39:13 +02:00
|
|
|
%token DEFAULT
|
2023-08-07 11:34:19 +02:00
|
|
|
%token FACILITY FASTCGI FOR_HOST
|
2021-07-19 09:39:13 +02:00
|
|
|
%token INCLUDE INDEX IPV6
|
|
|
|
%token KEY
|
2024-01-30 10:30:50 +01:00
|
|
|
%token LANG LISTEN LOCATION LOG
|
2021-10-15 08:30:42 +02:00
|
|
|
%token OCSP OFF ON
|
2022-01-02 17:33:28 +01:00
|
|
|
%token PARAM PORT PREFORK PROTO PROTOCOLS PROXY
|
2021-12-29 21:36:54 +01:00
|
|
|
%token RELAY_TO REQUIRE RETURN ROOT
|
2023-07-25 22:07:26 +02:00
|
|
|
%token SERVER SNI SOCKET STRIP STYLE SYSLOG
|
2022-02-26 15:00:20 +01:00
|
|
|
%token TCP TOEXT TYPE TYPES
|
2022-01-01 21:16:14 +01:00
|
|
|
%token USE_TLS USER
|
2022-01-01 19:50:10 +01:00
|
|
|
%token VERIFYNAME
|
2021-04-29 21:13:16 +02:00
|
|
|
|
2021-07-09 13:25:25 +02:00
|
|
|
%token ERROR
|
2021-01-15 10:17:43 +01:00
|
|
|
|
2021-07-09 13:25:25 +02:00
|
|
|
%token <v.string> STRING
|
|
|
|
%token <v.number> NUM
|
2021-01-15 10:17:43 +01:00
|
|
|
|
2022-10-05 17:10:44 +02:00
|
|
|
%type <v.number> bool proxy_port
|
2023-06-23 23:59:11 +02:00
|
|
|
%type <v.string> string numberstring listen_addr
|
2021-06-29 18:10:10 +02:00
|
|
|
|
2021-01-15 10:17:43 +01:00
|
|
|
%%
|
|
|
|
|
2021-06-29 14:42:44 +02:00
|
|
|
conf : /* empty */
|
2024-01-26 17:54:58 +01:00
|
|
|
| conf include nl
|
|
|
|
| conf varset nl
|
|
|
|
| conf option nl
|
|
|
|
| conf vhost nl
|
|
|
|
| conf types nl
|
|
|
|
| conf error nl { file->errors++; }
|
2021-06-29 14:17:40 +02:00
|
|
|
;
|
|
|
|
|
2021-07-09 13:25:25 +02:00
|
|
|
include : INCLUDE STRING {
|
|
|
|
struct file *nfile;
|
|
|
|
|
|
|
|
if ((nfile = pushfile($2, 0)) == NULL) {
|
|
|
|
yyerror("failed to include file %s", $2);
|
|
|
|
free($2);
|
|
|
|
YYERROR;
|
|
|
|
}
|
|
|
|
free($2);
|
|
|
|
|
|
|
|
file = nfile;
|
|
|
|
lungetc('\n');
|
|
|
|
}
|
|
|
|
;
|
|
|
|
|
2021-07-19 09:39:13 +02:00
|
|
|
bool : ON { $$ = 1; }
|
|
|
|
| OFF { $$ = 0; }
|
2021-07-09 13:25:25 +02:00
|
|
|
;
|
|
|
|
|
|
|
|
string : string STRING {
|
2021-06-29 18:10:10 +02:00
|
|
|
if (asprintf(&$$, "%s%s", $1, $2) == -1) {
|
|
|
|
free($1);
|
|
|
|
free($2);
|
|
|
|
yyerror("string: asprintf: %s", strerror(errno));
|
|
|
|
YYERROR;
|
|
|
|
}
|
|
|
|
free($1);
|
|
|
|
free($2);
|
|
|
|
}
|
2021-07-09 13:25:25 +02:00
|
|
|
| STRING
|
2021-06-29 18:10:10 +02:00
|
|
|
;
|
|
|
|
|
2022-02-26 15:00:20 +01:00
|
|
|
numberstring : NUM {
|
|
|
|
char *s;
|
|
|
|
if (asprintf(&s, "%d", $1) == -1) {
|
|
|
|
yyerror("asprintf: number");
|
|
|
|
YYERROR;
|
|
|
|
}
|
|
|
|
$$ = s;
|
|
|
|
}
|
|
|
|
| STRING
|
|
|
|
;
|
|
|
|
|
2021-07-09 13:25:25 +02:00
|
|
|
varset : STRING '=' string {
|
2021-06-29 14:17:40 +02:00
|
|
|
char *s = $1;
|
|
|
|
while (*s++) {
|
2021-07-09 13:25:25 +02:00
|
|
|
if (isspace((unsigned char)*s)) {
|
2021-06-29 14:17:40 +02:00
|
|
|
yyerror("macro name cannot contain "
|
|
|
|
"whitespaces");
|
|
|
|
free($1);
|
|
|
|
free($3);
|
|
|
|
YYERROR;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
symset($1, $3, 0);
|
|
|
|
free($1);
|
|
|
|
free($3);
|
|
|
|
}
|
|
|
|
;
|
2021-01-15 10:17:43 +01:00
|
|
|
|
2022-09-10 11:21:09 +02:00
|
|
|
option : CHROOT string {
|
2023-06-09 19:18:04 +02:00
|
|
|
if (strlcpy(conf->chroot, $2, sizeof(conf->chroot)) >=
|
|
|
|
sizeof(conf->chroot))
|
2022-09-10 11:21:09 +02:00
|
|
|
yyerror("chroot path too long");
|
|
|
|
free($2);
|
|
|
|
}
|
2023-06-23 23:03:29 +02:00
|
|
|
| IPV6 bool {
|
|
|
|
yywarn("option `ipv6' is deprecated,"
|
|
|
|
" please use `listen on'");
|
|
|
|
if ($2)
|
2023-08-25 14:19:00 +02:00
|
|
|
default_host = NULL;
|
2023-06-23 23:03:29 +02:00
|
|
|
else
|
|
|
|
default_host = "0.0.0.0";
|
|
|
|
}
|
2023-07-24 10:50:49 +02:00
|
|
|
| log
|
2023-06-23 23:03:29 +02:00
|
|
|
| PORT NUM {
|
|
|
|
yywarn("option `port' is deprecated,"
|
|
|
|
" please use `listen on'");
|
|
|
|
default_port = $2;
|
|
|
|
}
|
2023-06-09 19:18:04 +02:00
|
|
|
| PREFORK NUM { conf->prefork = check_prefork_num($2); }
|
2021-07-19 09:39:13 +02:00
|
|
|
| PROTOCOLS string {
|
2023-06-09 19:18:04 +02:00
|
|
|
if (tls_config_parse_protocols(&conf->protos, $2) == -1)
|
2021-02-10 12:53:05 +01:00
|
|
|
yyerror("invalid protocols string \"%s\"", $2);
|
2022-01-01 20:10:00 +01:00
|
|
|
free($2);
|
2021-01-15 19:55:05 +01:00
|
|
|
}
|
2022-09-10 11:21:09 +02:00
|
|
|
| USER string {
|
2023-06-09 19:18:04 +02:00
|
|
|
if (strlcpy(conf->user, $2, sizeof(conf->user)) >=
|
|
|
|
sizeof(conf->user))
|
2022-09-10 11:21:09 +02:00
|
|
|
yyerror("user name too long");
|
|
|
|
free($2);
|
|
|
|
}
|
2021-01-15 10:17:43 +01:00
|
|
|
;
|
|
|
|
|
2023-07-24 10:50:49 +02:00
|
|
|
log : LOG '{' optnl logopts '}'
|
|
|
|
| LOG logopt
|
|
|
|
;
|
|
|
|
|
|
|
|
logopts : /* empty */
|
|
|
|
| logopts logopt optnl
|
|
|
|
;
|
|
|
|
|
2023-08-07 11:08:23 +02:00
|
|
|
logopt : ACCESS string {
|
2023-07-24 10:50:49 +02:00
|
|
|
free(conf->log_access);
|
|
|
|
conf->log_access = $2;
|
|
|
|
}
|
2024-01-30 10:30:50 +01:00
|
|
|
| STYLE string {
|
|
|
|
if (!strcmp("combined", $2))
|
|
|
|
conf->log_format = LOG_FORMAT_COMBINED;
|
|
|
|
else if (!strcmp("common", $2))
|
|
|
|
conf->log_format = LOG_FORMAT_COMMON;
|
|
|
|
else if (!strcmp("condensed", $2))
|
|
|
|
conf->log_format = LOG_FORMAT_CONDENSED;
|
|
|
|
else if (!strcmp("legacy", $2))
|
|
|
|
conf->log_format = LOG_FORMAT_LEGACY;
|
|
|
|
else
|
|
|
|
yyerror("unknown log style: %s", $2);
|
|
|
|
free($2);
|
2023-07-25 22:07:26 +02:00
|
|
|
}
|
2023-08-07 11:34:19 +02:00
|
|
|
| SYSLOG FACILITY string {
|
|
|
|
const char *str = $3;
|
|
|
|
|
|
|
|
conf->log_syslog = 1;
|
|
|
|
|
|
|
|
if (!strncasecmp(str, "LOG_", 4))
|
|
|
|
str += 4;
|
|
|
|
|
|
|
|
if (!strcasecmp(str, "daemon"))
|
|
|
|
conf->log_facility = LOG_DAEMON;
|
|
|
|
#ifdef LOG_FTP
|
|
|
|
else if (!strcasecmp(str, "ftp"))
|
|
|
|
conf->log_facility = LOG_FTP;
|
|
|
|
#endif
|
|
|
|
else if (!strcasecmp(str, "local1"))
|
|
|
|
conf->log_facility = LOG_LOCAL1;
|
|
|
|
else if (!strcasecmp(str, "local2"))
|
|
|
|
conf->log_facility = LOG_LOCAL2;
|
|
|
|
else if (!strcasecmp(str, "local3"))
|
|
|
|
conf->log_facility = LOG_LOCAL3;
|
|
|
|
else if (!strcasecmp(str, "local4"))
|
|
|
|
conf->log_facility = LOG_LOCAL4;
|
|
|
|
else if (!strcasecmp(str, "local5"))
|
|
|
|
conf->log_facility = LOG_LOCAL5;
|
|
|
|
else if (!strcasecmp(str, "local6"))
|
|
|
|
conf->log_facility = LOG_LOCAL6;
|
|
|
|
else if (!strcasecmp(str, "local7"))
|
|
|
|
conf->log_facility = LOG_LOCAL7;
|
|
|
|
else if (!strcasecmp(str, "user"))
|
|
|
|
conf->log_facility = LOG_USER;
|
|
|
|
else
|
|
|
|
yywarn("unknown syslog facility `%s'",
|
|
|
|
$3);
|
|
|
|
|
|
|
|
free($3);
|
|
|
|
}
|
2023-08-07 11:08:23 +02:00
|
|
|
| SYSLOG OFF {
|
|
|
|
conf->log_syslog = 0;
|
|
|
|
}
|
|
|
|
| SYSLOG {
|
|
|
|
conf->log_syslog = 1;
|
|
|
|
}
|
2023-07-24 10:50:49 +02:00
|
|
|
;
|
|
|
|
|
2021-07-19 09:39:13 +02:00
|
|
|
vhost : SERVER string {
|
2021-03-31 18:32:18 +02:00
|
|
|
host = new_vhost();
|
2023-06-09 19:18:04 +02:00
|
|
|
TAILQ_INSERT_HEAD(&conf->hosts, host, vhosts);
|
2021-03-31 18:32:18 +02:00
|
|
|
|
|
|
|
loc = new_location();
|
|
|
|
TAILQ_INSERT_HEAD(&host->locations, loc, locations);
|
|
|
|
|
2022-01-02 17:33:28 +01:00
|
|
|
TAILQ_INIT(&host->proxies);
|
|
|
|
|
2022-10-05 17:10:44 +02:00
|
|
|
(void) strlcpy(loc->match, "*", sizeof(loc->match));
|
|
|
|
(void) strlcpy(host->domain, $2, sizeof(host->domain));
|
2021-01-15 10:17:43 +01:00
|
|
|
|
2021-01-28 17:27:40 +01:00
|
|
|
if (strstr($2, "xn--") != NULL) {
|
2021-07-13 13:30:54 +02:00
|
|
|
yywarn("\"%s\" looks like punycode: you "
|
|
|
|
"should use the decoded hostname", $2);
|
2021-01-28 17:27:40 +01:00
|
|
|
}
|
2022-10-05 17:10:44 +02:00
|
|
|
|
|
|
|
free($2);
|
2022-01-02 17:33:28 +01:00
|
|
|
} '{' optnl servbody '}' {
|
2023-06-08 21:34:49 +02:00
|
|
|
if (host->cert_path == NULL ||
|
|
|
|
host->key_path == NULL)
|
2023-06-23 18:23:59 +02:00
|
|
|
yyerror("invalid vhost definition: %s",
|
|
|
|
host->domain);
|
2023-06-23 23:03:29 +02:00
|
|
|
if (TAILQ_EMPTY(&host->addrs)) {
|
|
|
|
char portno[32];
|
|
|
|
int r;
|
|
|
|
|
|
|
|
r = snprintf(portno, sizeof(portno), "%d",
|
|
|
|
default_port);
|
|
|
|
if (r < 0 || (size_t)r >= sizeof(portno))
|
|
|
|
fatal("snprintf");
|
|
|
|
|
|
|
|
yywarn("missing `listen on' in server %s,"
|
2024-01-11 14:18:15 +01:00
|
|
|
" assuming %s port %d", host->domain,
|
2023-08-25 14:19:00 +02:00
|
|
|
default_host ? default_host : "*",
|
2023-06-23 23:03:29 +02:00
|
|
|
default_port);
|
|
|
|
listen_on(default_host, portno);
|
|
|
|
}
|
2021-01-15 10:17:43 +01:00
|
|
|
}
|
2021-07-13 13:30:54 +02:00
|
|
|
| error '}' { yyerror("bad server directive"); }
|
2021-01-15 10:17:43 +01:00
|
|
|
;
|
|
|
|
|
2022-01-02 17:33:28 +01:00
|
|
|
servbody : /* empty */
|
|
|
|
| servbody servopt optnl
|
|
|
|
| servbody location optnl
|
|
|
|
| servbody proxy optnl
|
2021-01-15 10:17:43 +01:00
|
|
|
;
|
|
|
|
|
2023-06-23 23:59:11 +02:00
|
|
|
listen_addr : '*' { $$ = NULL; }
|
|
|
|
| STRING
|
|
|
|
;
|
|
|
|
|
2021-07-19 09:39:13 +02:00
|
|
|
servopt : ALIAS string {
|
2021-04-29 20:23:35 +02:00
|
|
|
struct alist *a;
|
|
|
|
|
|
|
|
a = xcalloc(1, sizeof(*a));
|
2022-10-05 17:10:44 +02:00
|
|
|
(void) strlcpy(a->alias, $2, sizeof(a->alias));
|
|
|
|
free($2);
|
2022-09-10 12:12:37 +02:00
|
|
|
TAILQ_INSERT_TAIL(&host->aliases, a, aliases);
|
2021-04-29 20:23:35 +02:00
|
|
|
}
|
2021-07-19 09:39:13 +02:00
|
|
|
| CERT string {
|
2022-10-05 17:10:44 +02:00
|
|
|
ensure_absolute_path($2);
|
2023-06-08 21:34:49 +02:00
|
|
|
free(host->cert_path);
|
|
|
|
host->cert_path = $2;
|
2021-05-03 18:11:28 +02:00
|
|
|
}
|
2021-07-19 09:39:13 +02:00
|
|
|
| KEY string {
|
2022-10-05 17:10:44 +02:00
|
|
|
ensure_absolute_path($2);
|
2023-06-08 21:34:49 +02:00
|
|
|
free(host->key_path);
|
|
|
|
host->key_path = $2;
|
2021-05-03 18:11:28 +02:00
|
|
|
}
|
2021-10-15 08:30:42 +02:00
|
|
|
| OCSP string {
|
2022-10-05 17:10:44 +02:00
|
|
|
ensure_absolute_path($2);
|
2023-06-08 21:34:49 +02:00
|
|
|
free(host->ocsp_path);
|
|
|
|
host->ocsp_path = $2;
|
2021-10-15 08:30:42 +02:00
|
|
|
}
|
2021-07-19 09:39:13 +02:00
|
|
|
| PARAM string '=' string {
|
2023-07-23 20:45:05 +02:00
|
|
|
yywarn("the top-level `param' directive is deprecated."
|
|
|
|
" Please use `fastcgi { param ... }`");
|
2022-09-10 11:48:30 +02:00
|
|
|
add_param($2, $4);
|
2021-06-11 17:49:46 +02:00
|
|
|
}
|
2023-06-29 17:01:16 +02:00
|
|
|
| LISTEN ON listen_addr {
|
|
|
|
listen_on($3, "1965");
|
2023-08-25 14:19:49 +02:00
|
|
|
free($3);
|
2023-06-29 17:01:16 +02:00
|
|
|
}
|
2023-06-23 23:59:11 +02:00
|
|
|
| LISTEN ON listen_addr PORT STRING {
|
2023-06-23 23:03:29 +02:00
|
|
|
listen_on($3, $5);
|
|
|
|
free($3);
|
|
|
|
free($5);
|
|
|
|
}
|
2023-06-23 23:59:11 +02:00
|
|
|
| LISTEN ON listen_addr PORT NUM {
|
2023-06-23 23:03:29 +02:00
|
|
|
char portno[32];
|
|
|
|
int r;
|
|
|
|
|
|
|
|
r = snprintf(portno, sizeof(portno), "%d", $5);
|
|
|
|
if (r < 0 || (size_t)r >= sizeof(portno))
|
|
|
|
fatal("snprintf");
|
|
|
|
|
|
|
|
listen_on($3, portno);
|
|
|
|
free($3);
|
|
|
|
}
|
2021-01-24 15:11:40 +01:00
|
|
|
| locopt
|
|
|
|
;
|
|
|
|
|
2022-01-02 17:33:28 +01:00
|
|
|
proxy : PROXY { advance_proxy(); }
|
|
|
|
proxy_matches '{' optnl proxy_opts '}' {
|
2022-10-05 17:10:44 +02:00
|
|
|
if (*proxy->host == '\0')
|
2022-01-02 17:33:28 +01:00
|
|
|
yyerror("invalid proxy block: missing `relay-to' option");
|
|
|
|
|
2023-06-09 11:28:26 +02:00
|
|
|
if ((proxy->cert_path == NULL && proxy->key_path != NULL) ||
|
|
|
|
(proxy->cert_path != NULL && proxy->key_path == NULL))
|
2022-01-02 17:33:28 +01:00
|
|
|
yyerror("invalid proxy block: missing cert or key");
|
|
|
|
}
|
|
|
|
;
|
|
|
|
|
|
|
|
proxy_matches : /* empty */
|
|
|
|
| proxy_matches proxy_match
|
|
|
|
;
|
|
|
|
|
2022-10-05 17:10:44 +02:00
|
|
|
proxy_port : /* empty */ { $$ = 1965; }
|
|
|
|
| PORT STRING {
|
|
|
|
if (($$ = getservice($2)) == -1)
|
|
|
|
yyerror("invalid port number %s", $2);
|
|
|
|
free($2);
|
|
|
|
}
|
|
|
|
| PORT NUM { $$ = $2; }
|
|
|
|
;
|
|
|
|
|
2022-01-02 17:33:28 +01:00
|
|
|
proxy_match : PROTO string {
|
2022-10-05 17:10:44 +02:00
|
|
|
(void) strlcpy(proxy->match_proto, $2, sizeof(proxy->match_proto));
|
|
|
|
free($2);
|
2022-01-02 17:33:28 +01:00
|
|
|
}
|
2022-10-05 17:10:44 +02:00
|
|
|
| FOR_HOST string proxy_port {
|
|
|
|
(void) strlcpy(proxy->match_host, $2, sizeof(proxy->match_host));
|
|
|
|
(void) snprintf(proxy->match_port, sizeof(proxy->match_port),
|
|
|
|
"%d", $3);
|
|
|
|
free($2);
|
2022-01-02 17:33:28 +01:00
|
|
|
}
|
2022-01-01 18:08:39 +01:00
|
|
|
;
|
|
|
|
|
|
|
|
proxy_opts : /* empty */
|
|
|
|
| proxy_opts proxy_opt optnl
|
|
|
|
;
|
|
|
|
|
|
|
|
proxy_opt : CERT string {
|
2023-06-09 11:28:26 +02:00
|
|
|
free(proxy->cert);
|
2022-01-01 18:08:39 +01:00
|
|
|
ensure_absolute_path($2);
|
2023-06-09 11:28:26 +02:00
|
|
|
proxy->cert_path = $2;
|
2022-01-01 18:08:39 +01:00
|
|
|
}
|
|
|
|
| KEY string {
|
2023-06-09 11:28:26 +02:00
|
|
|
free(proxy->key);
|
2022-01-01 18:08:39 +01:00
|
|
|
ensure_absolute_path($2);
|
2023-06-09 11:28:26 +02:00
|
|
|
proxy->key_path = $2;
|
2022-01-01 18:08:39 +01:00
|
|
|
}
|
2022-01-01 20:04:50 +01:00
|
|
|
| PROTOCOLS string {
|
2022-01-02 17:33:28 +01:00
|
|
|
if (tls_config_parse_protocols(&proxy->protocols, $2) == -1)
|
2022-01-01 20:04:50 +01:00
|
|
|
yyerror("invalid protocols string \"%s\"", $2);
|
2022-01-01 20:10:00 +01:00
|
|
|
free($2);
|
2022-01-01 20:04:50 +01:00
|
|
|
}
|
2022-10-05 17:10:44 +02:00
|
|
|
| RELAY_TO string proxy_port {
|
|
|
|
(void) strlcpy(proxy->host, $2, sizeof(proxy->host));
|
|
|
|
(void) snprintf(proxy->port, sizeof(proxy->port),
|
|
|
|
"%d", $3);
|
|
|
|
free($2);
|
2022-01-01 18:08:39 +01:00
|
|
|
}
|
2022-01-05 00:14:34 +01:00
|
|
|
| REQUIRE CLIENT CA string {
|
|
|
|
ensure_absolute_path($4);
|
2023-06-09 11:28:26 +02:00
|
|
|
proxy->reqca_path = $4;
|
2022-01-05 00:14:34 +01:00
|
|
|
}
|
2022-01-30 11:14:44 +01:00
|
|
|
| SNI string {
|
2022-10-05 17:10:44 +02:00
|
|
|
(void) strlcpy(proxy->sni, $2, sizeof(proxy->sni));
|
|
|
|
free($2);
|
2022-01-30 11:14:44 +01:00
|
|
|
}
|
2022-01-01 21:16:14 +01:00
|
|
|
| USE_TLS bool {
|
2022-01-02 17:33:28 +01:00
|
|
|
proxy->notls = !$2;
|
2022-01-01 21:16:14 +01:00
|
|
|
}
|
2022-01-01 19:50:10 +01:00
|
|
|
| VERIFYNAME bool {
|
2022-01-02 17:33:28 +01:00
|
|
|
proxy->noverifyname = !$2;
|
2022-01-01 19:50:10 +01:00
|
|
|
}
|
2022-01-01 18:08:39 +01:00
|
|
|
;
|
|
|
|
|
2021-07-19 09:39:13 +02:00
|
|
|
location : LOCATION { advance_loc(); } string '{' optnl locopts '}' {
|
2021-02-10 17:37:08 +01:00
|
|
|
/* drop the starting '/' if any */
|
|
|
|
if (*$3 == '/')
|
|
|
|
memmove($3, $3+1, strlen($3));
|
2022-10-05 17:10:44 +02:00
|
|
|
(void) strlcpy(loc->match, $3, sizeof(loc->match));
|
|
|
|
free($3);
|
2021-01-24 15:11:40 +01:00
|
|
|
}
|
|
|
|
| error '}'
|
|
|
|
;
|
|
|
|
|
|
|
|
locopts : /* empty */
|
2021-07-09 13:25:25 +02:00
|
|
|
| locopts locopt optnl
|
2021-01-24 15:11:40 +01:00
|
|
|
;
|
|
|
|
|
2021-07-19 09:39:13 +02:00
|
|
|
locopt : AUTO INDEX bool { loc->auto_index = $3 ? 1 : -1; }
|
|
|
|
| BLOCK RETURN NUM string {
|
2022-10-05 17:10:44 +02:00
|
|
|
check_block_fmt($4);
|
|
|
|
(void) strlcpy(loc->block_fmt, $4, sizeof(loc->block_fmt));
|
2021-02-06 18:22:37 +01:00
|
|
|
loc->block_code = check_block_code($3);
|
2022-10-05 17:10:44 +02:00
|
|
|
free($4);
|
2021-02-06 18:22:37 +01:00
|
|
|
}
|
2021-07-19 09:39:13 +02:00
|
|
|
| BLOCK RETURN NUM {
|
2022-10-05 17:10:44 +02:00
|
|
|
(void) strlcpy(loc->block_fmt, "temporary failure",
|
|
|
|
sizeof(loc->block_fmt));
|
2021-02-06 18:22:37 +01:00
|
|
|
loc->block_code = check_block_code($3);
|
|
|
|
if ($3 >= 30 && $3 < 40)
|
|
|
|
yyerror("missing `meta' for block return %d", $3);
|
|
|
|
}
|
2021-07-19 09:39:13 +02:00
|
|
|
| BLOCK {
|
2022-10-05 17:10:44 +02:00
|
|
|
(void) strlcpy(loc->block_fmt, "temporary failure",
|
|
|
|
sizeof(loc->block_fmt));
|
2021-02-06 18:22:37 +01:00
|
|
|
loc->block_code = 40;
|
|
|
|
}
|
2021-07-19 09:39:13 +02:00
|
|
|
| DEFAULT TYPE string {
|
2022-10-05 17:10:44 +02:00
|
|
|
(void) strlcpy(loc->default_mime, $3,
|
|
|
|
sizeof(loc->default_mime));
|
|
|
|
free($3);
|
2021-02-09 23:38:10 +01:00
|
|
|
}
|
2023-07-23 20:45:05 +02:00
|
|
|
| fastcgi
|
2021-07-19 09:39:13 +02:00
|
|
|
| INDEX string {
|
2022-10-05 17:10:44 +02:00
|
|
|
(void) strlcpy(loc->index, $2, sizeof(loc->index));
|
|
|
|
free($2);
|
2021-02-09 23:38:10 +01:00
|
|
|
}
|
2021-07-19 09:39:13 +02:00
|
|
|
| LANG string {
|
2022-10-05 17:10:44 +02:00
|
|
|
(void) strlcpy(loc->lang, $2,
|
|
|
|
sizeof(loc->lang));
|
|
|
|
free($2);
|
2021-02-09 23:38:10 +01:00
|
|
|
}
|
2021-07-19 09:39:13 +02:00
|
|
|
| LOG bool { loc->disable_log = !$2; }
|
2022-01-01 17:33:40 +01:00
|
|
|
| REQUIRE CLIENT CA string {
|
|
|
|
ensure_absolute_path($4);
|
2023-06-09 11:28:26 +02:00
|
|
|
loc->reqca_path = $4;
|
2022-01-01 17:33:40 +01:00
|
|
|
}
|
|
|
|
| ROOT string {
|
2022-10-05 17:10:44 +02:00
|
|
|
(void) strlcpy(loc->dir, $2, sizeof(loc->dir));
|
|
|
|
free($2);
|
2022-01-01 17:33:40 +01:00
|
|
|
}
|
|
|
|
| STRIP NUM { loc->strip = check_strip_no($2); }
|
|
|
|
;
|
|
|
|
|
2023-07-23 20:45:05 +02:00
|
|
|
fastcgi : FASTCGI '{' optnl fastcgiopts '}'
|
|
|
|
| FASTCGI fastcgiopt
|
2023-07-23 21:04:37 +02:00
|
|
|
| FASTCGI OFF {
|
|
|
|
loc->fcgi = -1;
|
|
|
|
loc->nofcgi = 1;
|
|
|
|
}
|
2023-07-23 20:45:05 +02:00
|
|
|
| FASTCGI string {
|
|
|
|
yywarn("`fastcgi path' is deprecated. "
|
|
|
|
"Please use `fastcgi socket path' instead.");
|
|
|
|
loc->fcgi = fastcgi_conf($2, NULL);
|
|
|
|
free($2);
|
|
|
|
}
|
|
|
|
;
|
|
|
|
|
|
|
|
fastcgiopts : /* empty */
|
|
|
|
| fastcgiopts fastcgiopt optnl
|
|
|
|
;
|
|
|
|
|
|
|
|
fastcgiopt : PARAM string '=' string {
|
|
|
|
add_param($2, $4);
|
2021-05-24 11:09:10 +02:00
|
|
|
}
|
2023-07-23 20:45:05 +02:00
|
|
|
| SOCKET string {
|
|
|
|
loc->fcgi = fastcgi_conf($2, NULL);
|
|
|
|
free($2);
|
|
|
|
}
|
|
|
|
| SOCKET TCP string PORT NUM {
|
2021-05-24 11:09:10 +02:00
|
|
|
char *c;
|
2023-07-23 20:45:05 +02:00
|
|
|
|
|
|
|
if (asprintf(&c, "%d", $5) == -1)
|
2023-06-09 19:27:41 +02:00
|
|
|
fatal("asprintf");
|
2023-07-23 20:45:05 +02:00
|
|
|
loc->fcgi = fastcgi_conf($3, c);
|
|
|
|
free($3);
|
2023-07-23 19:43:27 +02:00
|
|
|
free(c);
|
2021-05-24 11:09:10 +02:00
|
|
|
}
|
2023-07-23 20:45:05 +02:00
|
|
|
| SOCKET TCP string {
|
|
|
|
loc->fcgi = fastcgi_conf($3, "9000");
|
2021-05-24 11:09:10 +02:00
|
|
|
}
|
2023-07-23 20:45:05 +02:00
|
|
|
| SOCKET TCP string PORT string {
|
|
|
|
loc->fcgi = fastcgi_conf($3, $5);
|
|
|
|
free($3);
|
|
|
|
free($5);
|
2021-05-24 11:09:10 +02:00
|
|
|
}
|
2023-08-08 19:35:11 +02:00
|
|
|
| STRIP NUM {
|
|
|
|
loc->fcgi_strip = $2;
|
|
|
|
}
|
2021-05-24 11:09:10 +02:00
|
|
|
;
|
|
|
|
|
2022-09-10 11:43:57 +02:00
|
|
|
types : TYPES '{' optnl mediaopts_l '}' ;
|
2022-02-26 15:00:20 +01:00
|
|
|
|
|
|
|
mediaopts_l : mediaopts_l mediaoptsl nl
|
|
|
|
| mediaoptsl nl
|
|
|
|
;
|
|
|
|
|
2022-09-10 11:40:05 +02:00
|
|
|
mediaoptsl : STRING {
|
|
|
|
free(current_media);
|
|
|
|
current_media = $1;
|
2024-01-26 17:54:58 +01:00
|
|
|
} medianames_l
|
2022-02-26 15:00:20 +01:00
|
|
|
| include
|
|
|
|
;
|
|
|
|
|
|
|
|
medianames_l : medianames_l medianamesl
|
|
|
|
| medianamesl
|
|
|
|
;
|
|
|
|
|
2022-04-08 15:44:49 +02:00
|
|
|
medianamesl : numberstring {
|
2023-06-09 19:18:04 +02:00
|
|
|
if (add_mime(&conf->mime, current_media, $1) == -1)
|
2023-06-09 19:27:41 +02:00
|
|
|
fatal("add_mime");
|
2022-09-10 11:40:05 +02:00
|
|
|
free($1);
|
2022-04-08 15:44:49 +02:00
|
|
|
}
|
2022-02-26 15:00:20 +01:00
|
|
|
;
|
|
|
|
|
|
|
|
nl : '\n' optnl
|
2024-01-26 17:54:58 +01:00
|
|
|
| ';' optnl
|
2022-02-26 15:00:20 +01:00
|
|
|
;
|
|
|
|
|
2024-01-26 17:54:58 +01:00
|
|
|
optnl : nl
|
2021-07-09 13:25:25 +02:00
|
|
|
| /*empty*/
|
|
|
|
;
|
2021-02-06 18:22:37 +01:00
|
|
|
|
2021-07-09 13:25:25 +02:00
|
|
|
%%
|
2021-01-27 17:45:45 +01:00
|
|
|
|
2022-03-19 12:02:42 +01:00
|
|
|
static const struct keyword {
|
2021-06-16 16:43:16 +02:00
|
|
|
const char *word;
|
|
|
|
int token;
|
|
|
|
} keywords[] = {
|
2021-07-08 20:30:19 +02:00
|
|
|
/* these MUST be sorted */
|
2023-07-24 10:50:49 +02:00
|
|
|
{"access", ACCESS},
|
2021-07-19 09:39:13 +02:00
|
|
|
{"alias", ALIAS},
|
|
|
|
{"auto", AUTO},
|
|
|
|
{"block", BLOCK},
|
|
|
|
{"ca", CA},
|
|
|
|
{"cert", CERT},
|
|
|
|
{"chroot", CHROOT},
|
|
|
|
{"client", CLIENT},
|
|
|
|
{"default", DEFAULT},
|
2023-08-07 11:34:19 +02:00
|
|
|
{"facility", FACILITY},
|
2021-07-19 09:45:55 +02:00
|
|
|
{"fastcgi", FASTCGI},
|
2022-01-02 17:33:28 +01:00
|
|
|
{"for-host", FOR_HOST},
|
2022-02-26 14:49:24 +01:00
|
|
|
{"include", INCLUDE},
|
2021-07-19 09:39:13 +02:00
|
|
|
{"index", INDEX},
|
|
|
|
{"ipv6", IPV6},
|
|
|
|
{"key", KEY},
|
|
|
|
{"lang", LANG},
|
2023-06-23 23:03:29 +02:00
|
|
|
{"listen", LISTEN},
|
2021-07-19 09:39:13 +02:00
|
|
|
{"location", LOCATION},
|
|
|
|
{"log", LOG},
|
2021-10-15 08:30:42 +02:00
|
|
|
{"ocsp", OCSP},
|
2021-07-19 09:39:13 +02:00
|
|
|
{"off", OFF},
|
|
|
|
{"on", ON},
|
|
|
|
{"param", PARAM},
|
|
|
|
{"port", PORT},
|
|
|
|
{"prefork", PREFORK},
|
2022-01-02 17:33:28 +01:00
|
|
|
{"proto", PROTO},
|
2021-07-19 09:39:13 +02:00
|
|
|
{"protocols", PROTOCOLS},
|
2021-12-29 21:36:54 +01:00
|
|
|
{"proxy", PROXY},
|
|
|
|
{"relay-to", RELAY_TO},
|
2021-07-19 09:39:13 +02:00
|
|
|
{"require", REQUIRE},
|
|
|
|
{"return", RETURN},
|
|
|
|
{"root", ROOT},
|
|
|
|
{"server", SERVER},
|
2022-01-30 11:14:44 +01:00
|
|
|
{"sni", SNI},
|
2023-07-23 20:45:05 +02:00
|
|
|
{"socket", SOCKET},
|
2021-07-19 09:39:13 +02:00
|
|
|
{"strip", STRIP},
|
2023-07-25 22:07:26 +02:00
|
|
|
{"style", STYLE},
|
2023-07-24 10:50:49 +02:00
|
|
|
{"syslog", SYSLOG},
|
2021-07-19 09:39:13 +02:00
|
|
|
{"tcp", TCP},
|
|
|
|
{"to-ext", TOEXT},
|
|
|
|
{"type", TYPE},
|
2022-02-26 15:00:20 +01:00
|
|
|
{"types", TYPES},
|
2022-01-01 21:16:14 +01:00
|
|
|
{"use-tls", USE_TLS},
|
2021-07-19 09:39:13 +02:00
|
|
|
{"user", USER},
|
2022-01-01 19:50:10 +01:00
|
|
|
{"verifyname", VERIFYNAME},
|
2021-06-16 16:43:16 +02:00
|
|
|
};
|
|
|
|
|
2021-07-09 13:25:25 +02:00
|
|
|
void
|
|
|
|
yyerror(const char *msg, ...)
|
|
|
|
{
|
|
|
|
va_list ap;
|
|
|
|
|
|
|
|
file->errors++;
|
|
|
|
|
|
|
|
va_start(ap, msg);
|
2021-07-13 13:30:54 +02:00
|
|
|
fprintf(stderr, "%s:%d error: ", config_path, yylval.lineno);
|
|
|
|
vfprintf(stderr, msg, ap);
|
|
|
|
fprintf(stderr, "\n");
|
|
|
|
va_end(ap);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
yywarn(const char *msg, ...)
|
|
|
|
{
|
|
|
|
va_list ap;
|
|
|
|
|
|
|
|
va_start(ap, msg);
|
|
|
|
fprintf(stderr, "%s:%d warning: ", config_path, yylval.lineno);
|
2021-07-09 13:25:25 +02:00
|
|
|
vfprintf(stderr, msg, ap);
|
|
|
|
fprintf(stderr, "\n");
|
|
|
|
va_end(ap);
|
|
|
|
}
|
|
|
|
|
2021-07-08 20:30:19 +02:00
|
|
|
int
|
|
|
|
kw_cmp(const void *k, const void *e)
|
|
|
|
{
|
|
|
|
return strcmp(k, ((struct keyword *)e)->word);
|
|
|
|
}
|
|
|
|
|
2021-07-09 13:25:25 +02:00
|
|
|
int
|
|
|
|
lookup(char *s)
|
2021-06-16 16:43:16 +02:00
|
|
|
{
|
2021-07-09 13:25:25 +02:00
|
|
|
const struct keyword *p;
|
2021-06-16 16:43:16 +02:00
|
|
|
|
2021-07-09 13:25:25 +02:00
|
|
|
p = bsearch(s, keywords, sizeof(keywords)/sizeof(keywords[0]),
|
|
|
|
sizeof(keywords[0]), kw_cmp);
|
2021-06-16 16:43:16 +02:00
|
|
|
|
2021-07-09 13:25:25 +02:00
|
|
|
if (p)
|
|
|
|
return p->token;
|
|
|
|
else
|
|
|
|
return STRING;
|
|
|
|
}
|
|
|
|
|
|
|
|
#define START_EXPAND 1
|
|
|
|
#define DONE_EXPAND 2
|
|
|
|
|
|
|
|
static int expanding;
|
|
|
|
|
|
|
|
int
|
|
|
|
igetc(void)
|
|
|
|
{
|
|
|
|
int c;
|
|
|
|
|
|
|
|
while (1) {
|
|
|
|
if (file->ungetpos > 0)
|
|
|
|
c = file->ungetbuf[--file->ungetpos];
|
|
|
|
else
|
|
|
|
c = getc(file->stream);
|
|
|
|
|
|
|
|
if (c == START_EXPAND)
|
|
|
|
expanding = 1;
|
|
|
|
else if (c == DONE_EXPAND)
|
|
|
|
expanding = 0;
|
|
|
|
else
|
|
|
|
break;
|
2021-06-16 16:43:16 +02:00
|
|
|
}
|
2021-07-09 13:25:25 +02:00
|
|
|
return c;
|
|
|
|
}
|
2021-06-16 16:43:16 +02:00
|
|
|
|
2021-07-09 13:25:25 +02:00
|
|
|
int
|
|
|
|
lgetc(int quotec)
|
|
|
|
{
|
|
|
|
int c, next;
|
|
|
|
|
|
|
|
if (quotec) {
|
|
|
|
if ((c = igetc()) == EOF) {
|
|
|
|
yyerror("reached end of file while parsing "
|
|
|
|
"quoted string");
|
|
|
|
if (file == topfile || popfile() == EOF)
|
|
|
|
return EOF;
|
|
|
|
return quotec;
|
|
|
|
}
|
2021-07-09 09:27:15 +02:00
|
|
|
return c;
|
2021-06-16 16:43:16 +02:00
|
|
|
}
|
|
|
|
|
2021-07-09 13:25:25 +02:00
|
|
|
while ((c = igetc()) == '\\') {
|
|
|
|
next = igetc();
|
|
|
|
if (next != '\n') {
|
|
|
|
c = next;
|
2021-06-16 16:43:16 +02:00
|
|
|
break;
|
2021-07-09 13:25:25 +02:00
|
|
|
}
|
|
|
|
yylval.lineno = file->lineno;
|
|
|
|
file->lineno++;
|
|
|
|
}
|
2021-06-29 14:17:40 +02:00
|
|
|
|
2021-07-09 13:25:25 +02:00
|
|
|
if (c == EOF) {
|
|
|
|
/*
|
|
|
|
* Fake EOL when hit EOF for the first time. This gets line
|
|
|
|
* count right if last line in included file is syntactically
|
|
|
|
* invalid and has no newline.
|
|
|
|
*/
|
|
|
|
if (file->eof_reached == 0) {
|
|
|
|
file->eof_reached = 1;
|
|
|
|
return '\n';
|
|
|
|
}
|
|
|
|
while (c == EOF) {
|
|
|
|
if (file == topfile || popfile() == EOF)
|
|
|
|
return EOF;
|
|
|
|
c = igetc();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return c;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
lungetc(int c)
|
|
|
|
{
|
|
|
|
if (c == EOF)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (file->ungetpos >= file->ungetsize) {
|
|
|
|
void *p = reallocarray(file->ungetbuf, file->ungetsize, 2);
|
|
|
|
if (p == NULL)
|
2023-06-06 13:52:43 +02:00
|
|
|
fatal("lungetc");
|
2021-07-09 13:25:25 +02:00
|
|
|
file->ungetbuf = p;
|
|
|
|
file->ungetsize *= 2;
|
|
|
|
}
|
|
|
|
file->ungetbuf[file->ungetpos++] = c;
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
findeol(void)
|
|
|
|
{
|
|
|
|
int c;
|
|
|
|
|
|
|
|
/* Skip to either EOF or the first real EOL. */
|
|
|
|
while (1) {
|
|
|
|
c = lgetc(0);
|
|
|
|
if (c == '\n') {
|
|
|
|
file->lineno++;
|
2021-06-29 14:17:40 +02:00
|
|
|
break;
|
2021-07-09 13:25:25 +02:00
|
|
|
}
|
|
|
|
if (c == EOF)
|
2021-06-16 16:43:16 +02:00
|
|
|
break;
|
2021-07-09 13:25:25 +02:00
|
|
|
}
|
|
|
|
return ERROR;
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
yylex(void)
|
|
|
|
{
|
2021-07-09 14:56:59 +02:00
|
|
|
char buf[8096];
|
|
|
|
char *p, *val;
|
|
|
|
int quotec, next, c;
|
|
|
|
int token;
|
2021-07-09 13:25:25 +02:00
|
|
|
|
|
|
|
top:
|
|
|
|
p = buf;
|
|
|
|
while ((c = lgetc(0)) == ' ' || c == '\t')
|
|
|
|
; /* nothing */
|
|
|
|
|
|
|
|
yylval.lineno = file->lineno;
|
|
|
|
if (c == '#')
|
|
|
|
while ((c = lgetc(0)) != '\n' && c != EOF)
|
|
|
|
; /* nothing */
|
|
|
|
if (c == '$' && !expanding) {
|
2021-07-09 14:49:15 +02:00
|
|
|
while (1) {
|
|
|
|
if ((c = lgetc(0)) == EOF)
|
|
|
|
return 0;
|
|
|
|
if (p + 1 >= buf + sizeof(buf) -1) {
|
|
|
|
yyerror("string too long");
|
|
|
|
return findeol();
|
|
|
|
}
|
|
|
|
if (isalnum(c) || c == '_') {
|
|
|
|
*p++ = c;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
*p = '\0';
|
|
|
|
lungetc(c);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
val = symget(buf);
|
|
|
|
if (val == NULL) {
|
|
|
|
yyerror("macro `%s' not defined", buf);
|
|
|
|
return findeol();
|
|
|
|
}
|
|
|
|
yylval.v.string = xstrdup(val);
|
|
|
|
return STRING;
|
|
|
|
}
|
|
|
|
if (c == '@' && !expanding) {
|
2021-07-09 13:25:25 +02:00
|
|
|
while (1) {
|
|
|
|
if ((c = lgetc(0)) == EOF)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
if (p + 1 >= buf + sizeof(buf) - 1) {
|
|
|
|
yyerror("string too long");
|
|
|
|
return findeol();
|
|
|
|
}
|
|
|
|
if (isalnum(c) || c == '_') {
|
|
|
|
*p++ = c;
|
2021-06-16 16:43:16 +02:00
|
|
|
continue;
|
|
|
|
}
|
2021-07-09 13:25:25 +02:00
|
|
|
*p = '\0';
|
|
|
|
lungetc(c);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
val = symget(buf);
|
|
|
|
if (val == NULL) {
|
|
|
|
yyerror("macro '%s' not defined", buf);
|
|
|
|
return findeol();
|
2021-06-16 16:43:16 +02:00
|
|
|
}
|
2021-07-09 13:25:25 +02:00
|
|
|
p = val + strlen(val) - 1;
|
|
|
|
lungetc(DONE_EXPAND);
|
|
|
|
while (p >= val) {
|
|
|
|
lungetc(*p);
|
|
|
|
p--;
|
2021-06-16 16:43:16 +02:00
|
|
|
}
|
2021-07-09 13:25:25 +02:00
|
|
|
lungetc(START_EXPAND);
|
|
|
|
goto top;
|
2021-06-16 16:43:16 +02:00
|
|
|
}
|
|
|
|
|
2021-07-09 13:25:25 +02:00
|
|
|
switch (c) {
|
|
|
|
case '\'':
|
|
|
|
case '"':
|
|
|
|
quotec = c;
|
|
|
|
while (1) {
|
|
|
|
if ((c = lgetc(quotec)) == EOF)
|
|
|
|
return 0;
|
|
|
|
if (c == '\n') {
|
|
|
|
file->lineno++;
|
|
|
|
continue;
|
|
|
|
} else if (c == '\\') {
|
|
|
|
if ((next = lgetc(quotec)) == EOF)
|
|
|
|
return (0);
|
|
|
|
if (next == quotec || next == ' ' ||
|
|
|
|
next == '\t')
|
|
|
|
c = next;
|
|
|
|
else if (next == '\n') {
|
|
|
|
file->lineno++;
|
|
|
|
continue;
|
|
|
|
} else
|
|
|
|
lungetc(next);
|
|
|
|
} else if (c == quotec) {
|
|
|
|
*p = '\0';
|
|
|
|
break;
|
|
|
|
} else if (c == '\0') {
|
2021-07-13 13:30:54 +02:00
|
|
|
yyerror("invalid syntax");
|
2021-07-09 13:25:25 +02:00
|
|
|
return findeol();
|
|
|
|
}
|
|
|
|
if (p + 1 >= buf + sizeof(buf) - 1) {
|
|
|
|
yyerror("string too long");
|
|
|
|
return findeol();
|
|
|
|
}
|
|
|
|
*p++ = c;
|
|
|
|
}
|
|
|
|
yylval.v.string = strdup(buf);
|
|
|
|
if (yylval.v.string == NULL)
|
2023-06-06 13:52:43 +02:00
|
|
|
fatal("yylex: strdup");
|
2021-07-09 13:25:25 +02:00
|
|
|
return STRING;
|
2021-06-16 16:43:16 +02:00
|
|
|
}
|
2021-07-09 13:25:25 +02:00
|
|
|
|
|
|
|
#define allowed_to_end_number(x) \
|
|
|
|
(isspace(x) || x == ')' || x ==',' || x == '/' || x == '}' || x == '=')
|
|
|
|
|
|
|
|
if (c == '-' || isdigit(c)) {
|
|
|
|
do {
|
|
|
|
*p++ = c;
|
|
|
|
if ((size_t)(p-buf) >= sizeof(buf)) {
|
|
|
|
yyerror("string too long");
|
|
|
|
return findeol();
|
|
|
|
}
|
|
|
|
} while ((c = lgetc(0)) != EOF && isdigit(c));
|
|
|
|
lungetc(c);
|
|
|
|
if (p == buf + 1 && buf[0] == '-')
|
|
|
|
goto nodigits;
|
|
|
|
if (c == EOF || allowed_to_end_number(c)) {
|
|
|
|
const char *errstr = NULL;
|
|
|
|
|
|
|
|
*p = '\0';
|
|
|
|
yylval.v.number = strtonum(buf, LLONG_MIN,
|
|
|
|
LLONG_MAX, &errstr);
|
|
|
|
if (errstr) {
|
|
|
|
yyerror("\"%s\" invalid number: %s",
|
|
|
|
buf, errstr);
|
|
|
|
return findeol();
|
|
|
|
}
|
|
|
|
return NUM;
|
|
|
|
} else {
|
|
|
|
nodigits:
|
|
|
|
while (p > buf + 1)
|
|
|
|
lungetc(*--p);
|
|
|
|
c = *--p;
|
|
|
|
if (c == '-')
|
|
|
|
return c;
|
|
|
|
}
|
2021-06-16 16:43:16 +02:00
|
|
|
}
|
2021-07-09 13:25:25 +02:00
|
|
|
|
|
|
|
#define allowed_in_string(x) \
|
|
|
|
(isalnum(x) || (ispunct(x) && x != '(' && x != ')' && \
|
|
|
|
x != '{' && x != '}' && \
|
|
|
|
x != '!' && x != '=' && x != '#' && \
|
2021-07-09 14:49:15 +02:00
|
|
|
x != ',' && x != ';'))
|
2021-07-09 13:25:25 +02:00
|
|
|
|
2021-07-09 14:49:15 +02:00
|
|
|
if (isalnum(c) || c == ':' || c == '_') {
|
2021-07-09 13:25:25 +02:00
|
|
|
do {
|
|
|
|
*p++ = c;
|
|
|
|
if ((size_t)(p-buf) >= sizeof(buf)) {
|
|
|
|
yyerror("string too long");
|
|
|
|
return findeol();
|
|
|
|
}
|
|
|
|
} while ((c = lgetc(0)) != EOF && (allowed_in_string(c)));
|
|
|
|
lungetc(c);
|
|
|
|
*p = '\0';
|
|
|
|
if ((token = lookup(buf)) == STRING)
|
|
|
|
yylval.v.string = xstrdup(buf);
|
|
|
|
return token;
|
2021-06-16 16:43:16 +02:00
|
|
|
}
|
2021-07-09 13:25:25 +02:00
|
|
|
if (c == '\n') {
|
|
|
|
yylval.lineno = file->lineno;
|
|
|
|
file->lineno++;
|
2021-06-16 16:43:16 +02:00
|
|
|
}
|
2021-07-09 13:25:25 +02:00
|
|
|
if (c == EOF)
|
|
|
|
return 0;
|
|
|
|
return c;
|
|
|
|
}
|
|
|
|
|
|
|
|
struct file *
|
|
|
|
pushfile(const char *name, int secret)
|
|
|
|
{
|
|
|
|
struct file *nfile;
|
|
|
|
|
|
|
|
nfile = xcalloc(1, sizeof(*nfile));
|
|
|
|
nfile->name = xstrdup(name);
|
|
|
|
if ((nfile->stream = fopen(nfile->name, "r")) == NULL) {
|
2023-06-06 13:46:40 +02:00
|
|
|
log_warn("can't open %s", nfile->name);
|
2021-07-09 13:25:25 +02:00
|
|
|
free(nfile->name);
|
|
|
|
free(nfile);
|
|
|
|
return NULL;
|
2021-06-16 16:43:16 +02:00
|
|
|
}
|
2021-07-09 13:25:25 +02:00
|
|
|
nfile->lineno = TAILQ_EMPTY(&files) ? 1 : 0;
|
|
|
|
nfile->ungetsize = 16;
|
|
|
|
nfile->ungetbuf = xcalloc(1, nfile->ungetsize);
|
|
|
|
TAILQ_INSERT_TAIL(&files, nfile, entry);
|
|
|
|
return nfile;
|
2021-06-16 16:43:16 +02:00
|
|
|
}
|
|
|
|
|
2021-01-27 17:45:45 +01:00
|
|
|
int
|
2021-07-09 13:25:25 +02:00
|
|
|
popfile(void)
|
2021-01-27 17:45:45 +01:00
|
|
|
{
|
2021-07-09 13:25:25 +02:00
|
|
|
struct file *prev;
|
|
|
|
|
|
|
|
if ((prev = TAILQ_PREV(file, files, entry)) != NULL)
|
|
|
|
prev->errors += file->errors;
|
|
|
|
|
|
|
|
TAILQ_REMOVE(&files, file, entry);
|
|
|
|
fclose(file->stream);
|
|
|
|
free(file->name);
|
|
|
|
free(file->ungetbuf);
|
|
|
|
free(file);
|
|
|
|
file = prev;
|
|
|
|
return file ? 0 : EOF;
|
2021-01-27 17:45:45 +01:00
|
|
|
}
|
|
|
|
|
2023-06-09 19:24:37 +02:00
|
|
|
int
|
2023-06-09 19:18:04 +02:00
|
|
|
parse_conf(struct conf *c, const char *filename)
|
2021-01-27 17:45:45 +01:00
|
|
|
{
|
2021-07-09 13:25:25 +02:00
|
|
|
struct sym *sym, *next;
|
2021-06-29 14:17:40 +02:00
|
|
|
|
2023-08-25 14:19:00 +02:00
|
|
|
default_host = NULL;
|
2023-06-23 23:03:29 +02:00
|
|
|
default_port = 1965;
|
|
|
|
|
2023-06-09 19:18:04 +02:00
|
|
|
conf = c;
|
|
|
|
|
2021-07-09 13:25:25 +02:00
|
|
|
file = pushfile(filename, 0);
|
|
|
|
if (file == NULL)
|
2023-06-09 19:24:37 +02:00
|
|
|
return -1;
|
2021-07-09 13:25:25 +02:00
|
|
|
topfile = file;
|
2021-03-31 18:32:18 +02:00
|
|
|
|
2021-07-09 13:25:25 +02:00
|
|
|
yyparse();
|
|
|
|
errors = file->errors;
|
|
|
|
popfile();
|
2021-06-29 14:17:40 +02:00
|
|
|
|
2021-07-09 13:25:25 +02:00
|
|
|
/* Free macros and check which have not been used. */
|
2021-06-29 14:17:40 +02:00
|
|
|
TAILQ_FOREACH_SAFE(sym, &symhead, entry, next) {
|
|
|
|
/* TODO: warn if !sym->used */
|
|
|
|
if (!sym->persist) {
|
|
|
|
free(sym->name);
|
|
|
|
free(sym->val);
|
|
|
|
TAILQ_REMOVE(&symhead, sym, entry);
|
|
|
|
free(sym);
|
|
|
|
}
|
|
|
|
}
|
2021-07-09 13:25:25 +02:00
|
|
|
|
|
|
|
if (errors)
|
2023-06-09 19:24:37 +02:00
|
|
|
return -1;
|
|
|
|
return 0;
|
2021-07-09 13:25:25 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
symset(const char *name, const char *val, int persist)
|
|
|
|
{
|
|
|
|
struct sym *sym;
|
|
|
|
|
|
|
|
TAILQ_FOREACH(sym, &symhead, entry) {
|
|
|
|
if (!strcmp(name, sym->name))
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (sym != NULL) {
|
|
|
|
if (sym->persist)
|
|
|
|
return 0;
|
|
|
|
else {
|
|
|
|
free(sym->name);
|
|
|
|
free(sym->val);
|
|
|
|
TAILQ_REMOVE(&symhead, sym, entry);
|
|
|
|
free(sym);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
sym = xcalloc(1, sizeof(*sym));
|
|
|
|
sym->name = xstrdup(name);
|
|
|
|
sym->val = xstrdup(val);
|
|
|
|
sym->used = 0;
|
|
|
|
sym->persist = persist;
|
|
|
|
|
|
|
|
TAILQ_INSERT_TAIL(&symhead, sym, entry);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
cmdline_symset(char *s)
|
|
|
|
{
|
|
|
|
char *sym, *val;
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
if ((val = strrchr(s, '=')) == NULL)
|
|
|
|
return -1;
|
|
|
|
sym = xcalloc(1, val - s + 1);
|
|
|
|
memcpy(sym, s, val - s);
|
|
|
|
ret = symset(sym, val + 1, 1);
|
|
|
|
free(sym);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
char *
|
|
|
|
symget(const char *nam)
|
|
|
|
{
|
|
|
|
struct sym *sym;
|
|
|
|
|
|
|
|
TAILQ_FOREACH(sym, &symhead, entry) {
|
|
|
|
if (strcmp(nam, sym->name) == 0) {
|
|
|
|
sym->used = 1;
|
|
|
|
return sym->val;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2021-02-01 12:08:57 +01:00
|
|
|
char *
|
|
|
|
ensure_absolute_path(char *path)
|
|
|
|
{
|
|
|
|
if (path == NULL || *path != '/')
|
2021-04-30 18:17:07 +02:00
|
|
|
yyerror("not an absolute path: %s", path);
|
2021-02-01 12:08:57 +01:00
|
|
|
return path;
|
|
|
|
}
|
2021-02-06 18:22:37 +01:00
|
|
|
|
|
|
|
int
|
|
|
|
check_block_code(int n)
|
|
|
|
{
|
|
|
|
if (n < 10 || n >= 70 || (n >= 20 && n <= 29))
|
|
|
|
yyerror("invalid block code %d", n);
|
|
|
|
return n;
|
|
|
|
}
|
|
|
|
|
|
|
|
char *
|
|
|
|
check_block_fmt(char *fmt)
|
|
|
|
{
|
|
|
|
char *s;
|
|
|
|
|
|
|
|
for (s = fmt; *s; ++s) {
|
|
|
|
if (*s != '%')
|
|
|
|
continue;
|
|
|
|
switch (*++s) {
|
|
|
|
case '%':
|
|
|
|
case 'p':
|
|
|
|
case 'q':
|
|
|
|
case 'P':
|
|
|
|
case 'N':
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
yyerror("invalid format specifier %%%c", *s);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return fmt;
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
check_strip_no(int n)
|
|
|
|
{
|
|
|
|
if (n <= 0)
|
|
|
|
yyerror("invalid strip number %d", n);
|
|
|
|
return n;
|
|
|
|
}
|
2021-02-07 13:05:32 +01:00
|
|
|
|
|
|
|
int
|
|
|
|
check_prefork_num(int n)
|
|
|
|
{
|
2023-06-08 15:59:31 +02:00
|
|
|
if (n <= 0 || n >= PROC_MAX_INSTANCES)
|
2021-02-07 13:05:32 +01:00
|
|
|
yyerror("invalid prefork number %d", n);
|
|
|
|
return n;
|
|
|
|
}
|
2021-02-10 17:37:08 +01:00
|
|
|
|
|
|
|
void
|
|
|
|
advance_loc(void)
|
|
|
|
{
|
2021-03-31 18:32:18 +02:00
|
|
|
loc = new_location();
|
|
|
|
TAILQ_INSERT_TAIL(&host->locations, loc, locations);
|
2021-02-10 17:37:08 +01:00
|
|
|
}
|
2021-05-03 18:11:28 +02:00
|
|
|
|
2022-01-02 17:33:28 +01:00
|
|
|
void
|
|
|
|
advance_proxy(void)
|
|
|
|
{
|
|
|
|
proxy = new_proxy();
|
|
|
|
TAILQ_INSERT_TAIL(&host->proxies, proxy, proxies);
|
|
|
|
}
|
|
|
|
|
2021-05-09 20:23:36 +02:00
|
|
|
int
|
2022-10-05 17:30:22 +02:00
|
|
|
fastcgi_conf(const char *path, const char *port)
|
2021-05-09 20:23:36 +02:00
|
|
|
{
|
|
|
|
struct fcgi *f;
|
2023-06-09 12:42:36 +02:00
|
|
|
int i = 0;
|
2021-05-09 20:23:36 +02:00
|
|
|
|
2023-06-09 19:18:04 +02:00
|
|
|
TAILQ_FOREACH(f, &conf->fcgi, fcgi) {
|
2021-05-09 20:23:36 +02:00
|
|
|
if (!strcmp(f->path, path) &&
|
2022-10-05 17:10:44 +02:00
|
|
|
((port == NULL && *f->port == '\0') ||
|
|
|
|
!strcmp(f->port, port)))
|
2021-05-09 20:23:36 +02:00
|
|
|
return i;
|
2023-06-09 12:42:36 +02:00
|
|
|
++i;
|
2021-05-09 20:23:36 +02:00
|
|
|
}
|
|
|
|
|
2023-06-09 12:42:36 +02:00
|
|
|
f = xcalloc(1, sizeof(*f));
|
|
|
|
f->id = i;
|
|
|
|
(void)strlcpy(f->path, path, sizeof(f->path));
|
|
|
|
if (port != NULL)
|
|
|
|
(void)strlcpy(f->port, port, sizeof(f->port));
|
2023-06-09 19:18:04 +02:00
|
|
|
TAILQ_INSERT_TAIL(&conf->fcgi, f, fcgi);
|
2023-06-09 12:42:36 +02:00
|
|
|
|
|
|
|
return f->id;
|
2021-05-09 20:23:36 +02:00
|
|
|
}
|
2021-06-11 17:49:46 +02:00
|
|
|
|
|
|
|
void
|
2022-09-10 11:48:30 +02:00
|
|
|
add_param(char *name, char *val)
|
2021-06-11 17:49:46 +02:00
|
|
|
{
|
|
|
|
struct envlist *e;
|
2023-07-23 20:45:05 +02:00
|
|
|
struct envhead *h = &loc->params;
|
2021-06-11 17:49:46 +02:00
|
|
|
|
|
|
|
e = xcalloc(1, sizeof(*e));
|
2022-10-05 17:10:44 +02:00
|
|
|
(void) strlcpy(e->name, name, sizeof(e->name));
|
|
|
|
(void) strlcpy(e->value, val, sizeof(e->value));
|
2022-09-10 12:12:37 +02:00
|
|
|
TAILQ_INSERT_TAIL(h, e, envs);
|
2021-06-11 17:49:46 +02:00
|
|
|
}
|
2022-10-05 17:10:44 +02:00
|
|
|
|
|
|
|
int
|
|
|
|
getservice(const char *n)
|
|
|
|
{
|
|
|
|
struct servent *s;
|
|
|
|
const char *errstr;
|
|
|
|
long long llval;
|
|
|
|
|
|
|
|
llval = strtonum(n, 0, UINT16_MAX, &errstr);
|
|
|
|
if (errstr) {
|
|
|
|
s = getservbyname(n, "tcp");
|
|
|
|
if (s == NULL)
|
|
|
|
s = getservbyname(n, "udp");
|
|
|
|
if (s == NULL)
|
|
|
|
return (-1);
|
|
|
|
return (ntohs(s->s_port));
|
|
|
|
}
|
|
|
|
|
|
|
|
return ((unsigned short)llval);
|
|
|
|
}
|
2023-06-23 23:03:29 +02:00
|
|
|
|
|
|
|
static void
|
2024-05-29 10:03:59 +02:00
|
|
|
add_to_addr_queue(struct addrhead *a, struct addrinfo *ai, const char *pp)
|
2023-06-23 23:03:29 +02:00
|
|
|
{
|
|
|
|
struct address *addr;
|
|
|
|
struct sockaddr_in *sin;
|
|
|
|
struct sockaddr_in6 *sin6;
|
|
|
|
|
|
|
|
if (ai->ai_addrlen > sizeof(addr->ss))
|
|
|
|
fatalx("ai_addrlen larger than a sockaddr_storage");
|
|
|
|
|
|
|
|
TAILQ_FOREACH(addr, a, addrs) {
|
|
|
|
if (addr->ai_flags == ai->ai_flags &&
|
|
|
|
addr->ai_family == ai->ai_family &&
|
|
|
|
addr->ai_socktype == ai->ai_socktype &&
|
|
|
|
addr->ai_protocol == ai->ai_protocol &&
|
|
|
|
addr->slen == ai->ai_addrlen &&
|
|
|
|
!memcmp(&addr->ss, ai->ai_addr, addr->slen))
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
addr = xcalloc(1, sizeof(*addr));
|
|
|
|
addr->ai_flags = ai->ai_flags;
|
|
|
|
addr->ai_family = ai->ai_family;
|
|
|
|
addr->ai_socktype = ai->ai_socktype;
|
|
|
|
addr->ai_protocol = ai->ai_protocol;
|
|
|
|
addr->slen = ai->ai_addrlen;
|
|
|
|
memcpy(&addr->ss, ai->ai_addr, ai->ai_addrlen);
|
2024-05-29 10:03:59 +02:00
|
|
|
strlcpy(addr->pp, pp, sizeof(addr->pp));
|
2023-06-23 23:03:29 +02:00
|
|
|
|
|
|
|
/* for commodity */
|
|
|
|
switch (addr->ai_family) {
|
|
|
|
case AF_INET:
|
|
|
|
sin = (struct sockaddr_in *)&addr->ss;
|
|
|
|
addr->port = ntohs(sin->sin_port);
|
|
|
|
break;
|
|
|
|
case AF_INET6:
|
|
|
|
sin6 = (struct sockaddr_in6 *)&addr->ss;
|
|
|
|
addr->port = ntohs(sin6->sin6_port);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
fatalx("unknown socket family %d", addr->ai_family);
|
|
|
|
}
|
|
|
|
|
|
|
|
addr->sock = -1;
|
|
|
|
|
|
|
|
TAILQ_INSERT_HEAD(a, addr, addrs);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
listen_on(const char *hostname, const char *servname)
|
|
|
|
{
|
|
|
|
struct addrinfo hints, *res, *res0;
|
2024-05-29 10:03:59 +02:00
|
|
|
char pp[NI_MAXHOST];
|
2023-06-23 23:03:29 +02:00
|
|
|
int error;
|
|
|
|
|
|
|
|
memset(&hints, 0, sizeof(hints));
|
|
|
|
hints.ai_family = AF_UNSPEC;
|
|
|
|
hints.ai_socktype = SOCK_STREAM;
|
|
|
|
hints.ai_flags = AI_PASSIVE;
|
|
|
|
error = getaddrinfo(hostname, servname, &hints, &res0);
|
|
|
|
if (error) {
|
|
|
|
yyerror("listen on \"%s\" port %s: %s", hostname, servname,
|
|
|
|
gai_strerror(errno));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (res = res0; res; res = res->ai_next) {
|
2024-05-29 10:03:59 +02:00
|
|
|
if (getnameinfo(res->ai_addr, res->ai_addrlen, pp, sizeof(pp),
|
|
|
|
NULL, 0, NI_NUMERICHOST) == -1) {
|
|
|
|
yyerror("getnameinfo failed: %s", strerror(errno));
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
add_to_addr_queue(&host->addrs, res, pp);
|
|
|
|
add_to_addr_queue(&conf->addrs, res, pp);
|
2023-06-23 23:03:29 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
freeaddrinfo(res0);
|
|
|
|
}
|